When trying to write to a file in Python, I do not get an error or anything, but the file written to remains blank, even though the data being written to the file is able to be printed. I have searched for this but no answers given to similar questions have worked for me.
My code is below (simplified to the parts that are affected):
with open(sourcefile, mode=readmode, encoding=encoding) as f1, open(targetfile, mode="a", encoding=encoding) as f2:
print(f1.read()); f2.write(f1.read())
I have tried using f2.flush(), other modes of writing (a, a+, w, w+), and none have worked. I have never encountered this problem before, so some assistance would be welcome.
The code is also part of a larger function, but only the code above is being run at the moment (other code is behind selection not currently being fulfilled.)
Thank you!
Edit: The submitted answer helps, although the print was added for debugging, it was causing issues when I didn't remove it after seemingly fixing the first issue. Thanks to this, I have been saved from countless other errors during the code as a result.