在Python中,是否有一个简洁的方法来比较两个文本文件的内容是否相同? [英] In Python, is there a concise way of comparing whether the contents of two text files are the same?
本文介绍了在Python中,是否有一个简洁的方法来比较两个文本文件的内容是否相同?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我不在乎差异是什么。我只想知道内容是否不同。
I don't care what the differences are. I just want to know whether the contents are different.
推荐答案
低级方法:
from __future__ import with_statement
with open(filename1) as f1:
with open(filename2) as f2:
if f1.read() == f2.read():
...
方式:
import filecmp
if filecmp.cmp(filename1, filename2, shallow=False):
...
这篇关于在Python中,是否有一个简洁的方法来比较两个文本文件的内容是否相同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文