Does Python do try: except: finally: ?

Skip Montanaro skip at pobox.com
Wed Mar 19 22:02:11 CET 2003


    Jerry> Does Python do a block like:
    Jerry> try:
    Jerry>     do_something()
    Jerry> except:
    Jerry>     do_something_else()
    Jerry> finally:
    Jerry>     do_cleanup()

Nope.

    Jerry> To get around this I do:

    Jerry> try:
    Jerry>     try:
    Jerry>         do_something()
    Jerry>     except:
    Jerry>         do_something_else()
    Jerry> finally:
    Jerry>     do_cleanup()

    Jerry> Is this the way it has to be done?

Yup.

Skip





More information about the Python-list mailing list