Does Python do try: except: finally: ?

Peter Hansen peter at engcorp.com
Thu Mar 20 06:34:59 EST 2003


Ulrich Petri wrote:
> 
> I allways asked myself of what practical use finally (except the syntactical
> "clearness of code") is?
> I can simply write like:
> 
> try:
>     do_this()
> except:
>     print "error"
> #now here is what will be executed next, so what for i do need finally?

Nobody seems to have answered this yet.  You are wrong about 
what will happen... if the print fails.  Okay, maybe your
example cannot fail, but in case it did, your so-called
"finally" code will never get executed!

-Peter




More information about the Python-list mailing list