Opening files without closing them
3c273
nospam at nospam.com
Mon Mar 6 16:47:17 EST 2006
"Erik Max Francis" <max at alcyone.com> wrote in message
news:wPCdnSJq7ObP5pbZnZ2dnUVZ_sSdnZ2d at speakeasy.net...
> Note quite. The assignment of the resources to its variable needs to be
> done before the try:
>
> f = open(file)
> try:
> contents = f.read()
> finally:
> f.close()
>
Pardon the newbie question, but could you explain why? I have been doing it
the same way as the OP and would like to know the difference. Thank you.
Louis
More information about the Python-list
mailing list