I created an empty file as follows:
touch foo.txt
Then, I opened up a Python interactive session, and typed the following:
>>> f = open("foo.txt", "w")
>>> print("Hello", file=f)
At this point, in another terminal, I typed the following:
rm foo.txt
Now, back in the Python interactive session, I typed:
>>> print("World", file=f)
This did not give an error. Why not? The file at this point has been deleted. So how is it still working?
Then, I tried the following in the same Python interactive session:
>>> f.close()
>>> f = open("foo.txt")
Now, the second of the above two statements gave an error, saying "No such file or directory 'foo.txt'". Why is it giving an error now? If the file still existed even after the rm command, why is trying to open the file failing?