I have code similar to:
with open('folder/file.txt', 'w') as file:
file.write(json.dumps(someJsonData))
In my program, each instance has a user. This particular code is inside a loop that edits the data files of multiple other users and always the current user with is code. The code works fine on the other users, but the current user's file never changes, even though I can verify that it did run and that it gives no error messages. Considering that I have opened and closed this file before in the program, I could have forgotten to close it, but I can not find a place where I did not (I did not use a with
the entire time to open a file).
Once before I had a similar issue in a different language and was able to print a hidden error message.
Is there a way I could print every output of this bit of code? For example, it might say "Successfully wrote to the file", or "Warning: Could not open the file". Could you do some sort of try-catch thing to always get a printable output?