difflib Python序列差异比较库

difflib序列差异比较

difflib,是Python的标准库,无需安装,使用的使用直接使用import difflib导入即可。difflib可以用于比较python序列或其它文件,并可以生成各种格式的文件差异信息,包括HTML和上下文以及统一差异。

difflib的简单应用实例

>>> import sys
>>> from difflib import *
>>> text1 = ['python','html','golang','css','javascript']
>>> text2 = ['Python','x1y1z1,com','笨鸟工具','machine learning','Deep Learning']
>>> sys.stdout.writelines(context_diff(text1,text2))
***
---
***************
*** 1,5 ****
! python! html! golang! css! javascript--- 1,5 ----
! Python! x1y1z1,com! 笨鸟工具! machine learning! Deep Learning

text3 = ['python','x1y1z1,com','笨鸟工具','machine learning','Deep Learning']
>>> sys.stdout.writelines(context_diff(text1,text3))
***
---
***************
*** 1,5 ****
  python! html! golang! css! javascript--- 1,5 ----
  python! x1y1z1,com! 笨鸟工具! machine learning! Deep Learning

免责声明:内容编辑自网络,仅供参考,不保证正确性,不作任何决策依据!!以上数据皆截止于博文的写稿日期。


行业导航 / Python指南 :
























Copyright © 2022-2024 笨鸟工具 x1y1z1.com All Rights Reserved.