Regarding exception handling

Fredrik Lundh fredrik at pythonware.com
Mon Jan 31 02:04:24 EST 2005


"Bryan" wrote

> the above is not the same. make the a = ... raise an exception and you'll see the difference.
>
> s = ... #
> a = 1/0
> s.close()
>
> as you can see, s.close() will never be called.  also, in this example, i intentionally didn't put 
> the extra try/except around the try/finally statement.

file handles and sockets are closed when the objects are garbage collected.
under CPython, they're usually closed when they go out of scope.

using try/finally on files and sockets are usually overkill.

</F> 






More information about the Python-list mailing list