首页 > 编程语言 > 详细

学习python自动化运维diff-text

时间:2015-08-12 19:54:13      阅读:193      评论:0      收藏:0      [点我收藏+]

1.通过html 比较diff_text两文本不同之处

#!/usr/bin/env python


import difflib


text1 = """text1:

This module provides classes and functions for comparing sequences.

including HTML and context and unified diffs.

difflib document v7.4

add string

"""

text1_lines = text1.splitlines()

text2 = """text2:

This module provides classes and functions for Comparing sequences.

including HTML and context and unified diffs.

difflib document v7.5

"""


text2_lines = text2.splitlines()


d = difflib.HtmlDiff()

print d.make_file(text1_lines, text2_lines)


2. 通过差异关系符比较

#!/usr/bin/env python


import difflib


text1 = """text1:

This module provides classes and functions for comparing sequences.

including HTML and context and unified diffs.

difflib document v7.4

add string

"""

text1_lines = text1.splitlines()

text2 = """text2:

This module provides classes and functions for Comparing sequences.

including HTML and context and unified diffs.

difflib document v7.5

"""


text2_lines = text2.splitlines()


d = difflib.Differ()

diff = d.compare(text1_lines, text2_lines)

print ‘\n‘.join(list(diff))


学习python自动化运维diff-text

原文:http://yzg784534398.blog.51cto.com/9719002/1684026

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!