问题描述
我正在尝试使用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
然后发送邮件(我已经为邮件编写了代码)。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)