[MERGE][Win32] explicit close of file in textfile

Aaron Bentley aaron.bentley at utoronto.ca
Thu May 4 13:38:28 BST 2006


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Andrew Bennetts wrote:
| I believe a better style is this:
|
|     f = open(path, 'rb')
|     try:
|         text_file(f)
|     finally:
|         f.close()
|
| Otherwise an exception raised during the "open(path, 'rb')" (perhaps a
| permission error, or even a KeyboardInterrupt) will try to execute
"f.close()"
| when f is undefined.  This will cause an unnecessary NameError, and
prevent the
| original exception from propagating.

I agree completely.  Dunno what I was thinking.

Aaron
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFEWfXE0F+nu1YWqI0RAuc2AJ9PtS9gdDxVFeR70rdqSzRePNNBjQCfQTmt
h3cVdG12ZKoL5V6tGJL+yL4=
=YeL9
-----END PGP SIGNATURE-----




More information about the bazaar mailing list