技术宅,fat-man

增加语言的了解程度可以避免写出愚蠢的代码

导航

python 文本比较

#!/usr/bin/env python
#
-*- coding: utf-8 -*-
import difflib
from difflib import *

def compare(stream1,stream2):
lines1 = stream1.splitlines()
lines2 = stream2.splitlines()
result=list(Differ().compare(lines1,lines2))
print str(result)

if __name__ == '__main__':
s1="hello\nword\nwww\n"
s2="hello\nworld"
compare(s1,s2)

posted on 2012-03-13 14:40  codestyle  阅读(615)  评论(0编辑  收藏  举报