losing handles of open files

Ben Finney bignose+hates-spam at benfinney.id.au
Fri Jun 2 00:30:54 CEST 2006

Please don't post non-text message bodies to discussion
forums. Message bodies should be plain text.

"Anthra Norell" <anthra.norell at tiscalinet.ch> writes:

> If a piece of code exits with an exception before it closes an open
> file, that file seems to remain locked, which is real pain in the
> butt

You will want to examine the 'finally' clause, which is executed after
the 'try' suite regardless of exceptions.


You may also be interested in the 'with' statement, coming in Python
2.5, which will be a more natural way of expressing this idiom.


 \         "If nature has made any one thing less susceptible than all |
  `\    others of exclusive property, it is the action of the thinking |
_o__)                       power called an idea"  -- Thomas Jefferson |
Ben Finney

More information about the Python-list mailing list