python文本比较库difflib使用示例,pythondifflib,python的包很丰富,
python文本比较库difflib使用示例,pythondifflib,python的包很丰富,
python的包很丰富, difflib是用来做文本比较的,下面是一个使用例子:
import diffliblines1 = '''dogcatbirdbuffalogophershoundhorse'''.strip().splitlines()lines2 = '''catdogbirdbuffalogopherhorsemouse'''.strip().splitlines()# Changes:# swapped positions of cat and dog# changed gophers to gopher# removed hound# added mousefor line in difflib.unified_diff(lines1, lines2, fromfile='file1', tofile='file2', lineterm=''): print line
输出内容如下:
Outputs the following:--- file1+++ file2@@ -1,7 +1,7 @@+cat dog-cat bird buffalo-gophers-hound+gopher horse+mouse
这个类库也可以用来比较两个文本文件。
相关内容
- python 复制文件或者文件夹,,python提供了shu
- Python的线程控制类,Python线程控制类,下面是一个基础的
- Python实现的MAC系统下的剪贴板代码,pythonmac,This is a c
- python方法参数默认值示例,python默认值示例,def boxVolu
- python如何删除文件,文件夹,python删除文件,python删除文
- Python将jpeg或jpg图片转换为png图片,,python的pil库可
- python将png图片转换为jpeg图片,,如下代码使用PIL库将p
- Python判断图片是否是jpeg格式(非扩展名方式),,用扩
- django上传图片并生成缩略图代码示例,,django 处理上传
- python创建临时文件代码,python创建代码,python有一个te
评论关闭