Anonymous file closing

Paul Rubin http
Fri Jun 11 20:10:50 EDT 2004


Peter Hansen <peter at engcorp.com> writes:
> >> f = open(filename, 'r')
> >> try:
> >>     text = f.read()
> >> finally:
> >>     f.close()
> >>
> > But the uncertainty remains in case of an anonymous file, doesn't it?
> 
> What's an "anonymous file"?  The term means nothing to me...

I think it means the file descriptor created in a statement like

    text = open(filename, 'r').read()

It's hard to clean up such a descriptor in a finally clause.



More information about the Python-list mailing list