I am using python 3.7 ( on windows 10 ) I execute following line on terminal.
open('textfile.txt')
After I try to delete the file ('textfile.txt') then os said It is being used by some program. I close the terminal and open a new terminal then I execute following code
open('textfile.txt').read()
I try to delete the file ('textfile.txt') then It's deleted. My problem is both times I did't assign file object to any variable but first time file didn't close automatically second time It was happend.
Why second time python close the file automatically ?
_.open(path)and wait, then the file descriptor is stored in a variable, whileopen(path).read()binds the content of the file to a variable, but the file descriptor is not bound and can be garbage collected.