标签:odi out stdout style 疑问 含义 adl readline dir
#!/usr/bin/env python
#-*- coding:utf-8 -*-
import difflib
import sys,os
os.chdir(‘E:\\PythonWrok‘)
a = open(‘sayhi.txt‘,‘r‘).readlines()
b = open(‘hello.txt‘,‘r‘).readlines()
diff = difflib.ndiff(a, b)
sys.stdout.writelines(diff)
结果如下:
+ print "Hello world"- def sayhi(name):
- print "Hello %s ,Today is good day!" % name
- name = ‘liqian‘
- sayhi(name)
-
-
字符含义:
‘- ‘ 仅在片段1中存在
‘+ ‘ 仅在片段2中存在
‘ ‘ 片段1和2中都存在
‘? ‘ 存在疑问的
通常用于数据对比,校验文件内容
标签:odi out stdout style 疑问 含义 adl readline dir
原文地址:http://www.cnblogs.com/i1991/p/6769866.html