在python 下对比 2个文件中 的某一个文件缺少那些内容
#!/usr/bin/env python
#coding:utf8
def file(file_name):
fileA_list,fileB_list = [],[]
fileA_name,fileB_name = file_name.split()
with open(fileA_name) as fA:
for line in fA.readlines():
fileA_list.append(line.split())
with open(fileB_name) as fB:
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集合也是可以的,有需要也是可以