When I tried the following code in my IDE and in the command prompt with python test.py
, my text file was still empty afterward:
with open("test.txt", "r+") as file:
file.write("Hello World")
I was confused, because this worked before. So I tried the exact same code in the python console.
And voila, my text file test.txt
now contained the string Hello World
When I changed the content of the text file manually and tried to read it again with the program, the output was the string I tried to write earlier to the text file.
Is there some kind of delay when trying to write and read to and from a file when using a script in comparison to using the python console?