# coding=gbk
import filecmp
import os
def cmp_file_content(src_file_name, dst_file_name):
if not os.access(src_file_name, os.F_OK):
print '%s does not exist' %(src_file_name)
return -2
if not os.access(dst_file_name, os.F_OK):
print '%s does not exist' %(dst_file_name)
return -2
if (filecmp.cmp(src_file_name, dst_file_name)):
print ("%s %s content are same" %(src_file_name, dst_file_name))
return 0
else:
print ("%s %s content are not same" %(src_file_name, dst_file_name))
return -1
if __name__ == '__main__':
src_file_name = r'1.txt'
dst_file_name = r'2.txt'
cmp_file_content(src_file_name, dst_file_name)
import filecmp
import os
def cmp_file_content(src_file_name, dst_file_name):
if not os.access(src_file_name, os.F_OK):
print '%s does not exist' %(src_file_name)
return -2
if not os.access(dst_file_name, os.F_OK):
print '%s does not exist' %(dst_file_name)
return -2
if (filecmp.cmp(src_file_name, dst_file_name)):
print ("%s %s content are same" %(src_file_name, dst_file_name))
return 0
else:
print ("%s %s content are not same" %(src_file_name, dst_file_name))
return -1
if __name__ == '__main__':
src_file_name = r'1.txt'
dst_file_name = r'2.txt'
cmp_file_content(src_file_name, dst_file_name)