[Tutor] file opened by open() are closed automaticaly
ZEMMOURA Khalil Zakaria
zemmoura.khalil at gmail.com
Fri Jan 13 17:04:10 EST 2017
I am playing with python3.6 and i noticed a change in the behaviour of the open() builtin function.
The file opened using open() is closed automaticaly after iterationg over it in the python shell
Here is the dummy code i am using:
testfile = open('test.txt')
for line in testfile:
the first time the code runs well and gives me the expected result.
the secod time that i run the loop, nothing is printed on the screen.
when i type:
testfile.close and press the tab key to autocomplete:
here is what i get
>>> testfile.close( testfile.closed
when i run that commande and ignore the message:
nothing is prined on the terminal, and python runs the commande as if the file is still opened.
i searched in the doc and this behaviour is not documented.
I don't now if it is a bug or i didn't search in the right place.
More information about the Tutor