我试图在两个文件之间进行比较filecmp,问题是结果始终是"No, the files are NOT the same",这意味着False 即使文件是相同的。
我正在向两个不同的文件写入相同的内容。首先我写入文件revision_1.txt:
original_stdout = sys.stdout
with open('revision_1.txt', 'w') as rev1:
sys.stdout = rev1
print(revision) # revision is output from command i took before
sys.stdout = original_stdout
if filecmp.cmp('revision_1.txt', 'revision_2.txt'):
# revision_2.txt is file I c
print("Both the files are same")
else:
# Do whatever you want if the files are NOT the same
print("No, the files are NOT the same")
original_stdout = sys.stdout
with open('revision_2.txt', 'w') as rev2:
sys.stdout = rev2
print(revision) # revision is output from command i took before
sys.stdout = original_stdout
我的目标是如果文件相等 - 停止脚本。如果不是,它将重写revision_2.txt然后发送邮件,(我已经编写了邮件代码)。
小怪兽爱吃肉
皈依舞
慕雪6442864
相关分类