yangsuiyun / master-python

Python修炼大法
0 stars 0 forks source link

data diff #23

Open yangsuiyun opened 4 years ago

yangsuiyun commented 4 years ago

import difflib text1 = """text1: #定义字符串1 This module provides classes and functions for comparing sequences. including HTML and context and unified diffs."""

text1_lines = text1.splitlines() #以行进行分隔,以便进行对比 text2 = """text2: #定义第二个字符串 This module provides """

text2_lines = text2.splitlines() d = difflib.Differ() #创建Differ对象 diff = d.compare(text1.splitlines(), text2.splitlines()) #采用compare方法对字符串进行比较 print('\n'.join(list(diff)))