Does Python do try: except: finally: ?

Erik Max Francis max at alcyone.com
Wed Mar 19 17:15:20 EST 2003


Joseph Wilhelm wrote:

> >>> try:
> ...     print "Foo"
> ... except:
> ...     print "Oof"
> ... else:
> ...     print "Bar"
> ...
> Foo
> Bar
> >>>
> 
> That what you need?

Probably not:

>>> try:
...  print 'foo'
...  raise ValueError
... except:
...  print 'oof'
... else:
...  print 'bar'
... 
foo
oof

The else clause is only executed in the case where there's no error,
quite contrary to what is usually intended by a try..except...finally
clause.

-- 
 Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/
 __ San Jose, CA, USA / 37 20 N 121 53 W / &tSftDotIotE
/  \ Patriotism is the virtue of the vicious.
\__/ Oscar Wilde
    Bosskey.net: Counter-Strike / http://www.bosskey.net/cs/
 A personal guide to Counter-Strike.




More information about the Python-list mailing list