Re: Opening files without closing them
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.python archive

Re: Opening files without closing them

From: 3c273 <nospam@nospam.com>
Date: Mon Mar 06 2006 - 22:47:17 CET

"Erik Max Francis" <max@alcyone.com> wrote in message
news:wPCdnSJq7ObP5pbZnZ2dnUVZ_sSdnZ2d@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
Received on Sun Apr 30 11:01:19 2006