[Tutor] except AttributeError, TypeError:

Thorsten Kampe thorsten at thorstenkampe.de
Sat May 1 19:42:25 EDT 2004


What is the best way to except two errors, when the except handling in
both cases is the same?

"except:" would just except every error and not just those I want.

except Attribute error:
    do_much_stuff
except TypeError:
    do_the_same_stuff

is bad because of the duplication and

def do_it():
    do_much_stuff
except Attribute error:
    do_it()
except TypeError:
    do_it()

would work but is rather unelegant? What is the best way to except to
errors with the same exception handling?

Thorsten




More information about the Tutor mailing list