请问有人会数据科学吗。可以提供教学吗?怎么将两个file做对比,然后列出它们之间的关系。
1、比较文件内容
import difflib
with open('file1.txt', 'r') as f1, open('file2.txt', 'r') as f2:
diff = difflib.unified_diff(f1.readlines(), f2.readlines())
for line in diff:
print(line)
2、比较文件大小
import os
size1 = os.path.getsize('file1.txt')
size2 = os.path.getsize('file2.txt')
if size1 == size2:
print('The files are the same size.')
elif size1 > size2:
print('File 1 is larger than file 2.')
else:
print('File 2 is larger than file 1.')
3、比较文件修改时间
import os
mtime1 = os.path.getmtime('file1.txt')
mtime2 = os.path.getmtime('file2.txt')
if mtime1 == mtime2:
print('The files were modified at the same time.')
elif mtime1 > mtime2:
print('File 1 was modified more recently than file 2.')
else:
print('File 2 was modified more recently than file 1.')
望采纳