Apr-12-2021, 09:47 AM
It's possible that your file was not written where you expected it was going to be written.
That can be assured if you set the starting directory, or specify a full path (as below). The statement shown here
guarantees that the starting directory is the same as that of the script.
Also, using 'with' on your open statement will automatically close the file at end and is the preferred method to use:
That can be assured if you set the starting directory, or specify a full path (as below). The statement shown here
guarantees that the starting directory is the same as that of the script.
Also, using 'with' on your open statement will automatically close the file at end and is the preferred method to use:
import os os.chdir(os.path.abspath(os.path.dirname(__file__))) with open("test.txt","w") as test: test.write('test hello')