Anonymous file closing

Sergey Krushinsky skru at
Fri Jun 11 16:44:23 CEST 2004

Duncan Booth wrote:

>Yes it is closed, but it isn't well defined as to exactly when it is 
>closed. You can safely assume that the file will be closed sometime between 
>the read returning and your program exiting.
Is it also true when file object exists inside a function? Like:

def a():
    text = open(filename, 'r').read()

It would be natural if the file object's memory were freed after a() 


More information about the Python-list mailing list