python文本比较库difflib使用示例
发布时间:2020-05-29 00:54:13 所属栏目:Python 来源:互联网
导读:python文本比较库difflib使用示例
|
下面是脚本之家 jb51.cc 通过网络收集整理的代码片段。 脚本之家小编现在分享给大家,也给大家做个参考。 import difflib
lines1 = '''
dog
cat
bird
buffalo
gophers
hound
horse
'''.strip().splitlines()
lines2 = '''
cat
dog
bird
buffalo
gopher
horse
mouse
'''.strip().splitlines()
# Changes:
# swapped positions of cat and dog
# changed gophers to gopher
# removed hound
# added mouse
for 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 以上是脚本之家(jb51.cc)为你收集整理的全部代码内容,希望文章能够帮你解决所遇到的程序开发问题。 如果觉得脚本之家网站内容还不错,欢迎将脚本之家网站推荐给程序员好友。 (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
推荐文章
站长推荐
- 解决ImportError: No module named setuptools的
- python 命名空间与作用域入门实例
- 在Python中操作列表之list.extend()方法的使用
- python – 使用Django Admin中的UserProfile字段
- python – 如何编写依赖于子关系中的列的混合属性
- 详解Python的collections模块中的deque双端队列结
- python-Cython函数指针取消引用时间(与直接调用函
- python – 使用NTLM身份验证的Easy_install或pip
- 能否在设备上加载.gpx轨道以使用appium测试跟踪器
- python的id()函数解密过程
热点阅读
