在python 下對比 2個文件中 的某一個文件缺乏那些內容
python
#!/usr/bin/env pythonwindows
#coding:utf8app
def file(file_name):ide
fileA_list,fileB_list = [],[]rem
fileA_name,fileB_name = file_name.split()input
with open(fileA_name) as fA:源碼
for line in fA.readlines():it
fileA_list.append(line.split())class
with open(fileB_name) as fB:coding
for line in fB.readlines():
fileB_list.append(line.split())
return fileA_list,fileB_list
def func():
fileA_list,fileB_list = file(file_name)
if len(fileA_list) > len(fileB_list):
for line in fileB_list:
fileA_list.remove(line)
print fileA_list
else:
for line in fileA_list:
fileB_list.remove(line)
print fileB_list
if __name__=='__main__':
print "input two files"
file_name = raw_input("Enter the two files you need to compare:")
func()
附上源碼:
也有exe格式的 能夠在windows下執行 不過只能是英文的 中文的執行不了
python中的set集合也是能夠的,有須要也是能夠