ファイルを比較
テキストファイルを比較する - imaitの日記
という記事を見つけたのですが、
単にファイルの一致を確認するだけなら、もっと簡潔に比較できると思います。
テキストに限らない、一般のファイルを。
from contextlib import nested def samefile(path1, path2, bufsize=64*1014): with nested(open(path1, "rb"), file(path2, "rb")) as (fp1, fp2): while 1: c1 = fp1.read(bufsize) c2 = fp2.read(bufsize) if c1 != c2: return False if not c1: break return True