except AttributeError, TypeError:
John Roth
newsgroups at jhrothjr.com
Sat May 1 19:59:00 EDT 2004
"Thorsten Kampe" <thorsten at thorstenkampe.de> wrote in message
news:19zy0i7gw5uym.dlg at thorstenkampe.de...
> 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?
except (AttributeError, TypeError):
John Roth
>
> Thorsten
More information about the Python-list
mailing list