Does Python do try: except: finally: ?
danb_83 at yahoo.com
Thu Mar 20 04:08:29 CET 2003
"Ulrich Petri" <ulope at gmx.de> wrote in message news:<b5b0de$253ft3$1 at ID-67890.news.dfncis.de>...
> "Skip Montanaro" <skip at pobox.com> schrieb im Newsbeitrag
> news:mailman.1048112434.6123.python-list at python.org...
> > Maybe, but that's not what try/finally does. Try/finally says, "Execute
> > code in the try block, and irregardless of any exceptions which might get
> > raised, execute the code in the finally block when finished."
> > Try/except/else says, "Execute the code in the try block. If an exception
> > is raised, execute the code in the except block, otherwise execute the
> > in the else block."
> I allways asked myself of what practical use finally (except the syntactical
> "clearness of code") is?
> I can simply write like:
> print "error"
> #now here is what will be executed next, so what for i do need finally?
"finally" does affect control flow.
>>> def foo():
... return "spam"
... print "finally"
>>> print foo()
More information about the Python-list