I am on windows 10, python 3.8.
I have a python script that needs to write to a file. If I execute this script from the same directory ('python runScript.py'), everything works as expected (also in VSCode). When I try to run this script from another location ('python C:/myproject/runScript.py'), it will not write. However, everything else works normal. Like printing what I actually want to write.
I tried to simplify my code for debugging:
testaa = 'stringabc'
with open('temp.txt', 'w') as f:
f.write(testaa)
I tried .close() and .flush() as mentioned from other solutions.
What's going on?
temp.txttoC:in the other case?open('temp.txt', 'w')creates the file in the current directory, which is not necessarily the same as the directory where the python script lives.