I'm trying to compare between two files with filecmp
, the problem is that the result is always "No, the files are NOT the same"
which means False
even though the files are the same.
I'm writing to two different files the same content. First I write to file 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
My goal is if the files are equal - stop the script. If they are not, it will rewrite revision_2.txt
and then send mail, (I already wrote the code for mail).
sys.stdout
so much? Why not just dofile.write(...)
? – Tomerikoo