catching exceptions from an except: block
Bruno Desthuilliers
bdesth.quelquechose at free.quelquepart.fr
Wed Mar 7 17:00:59 EST 2007
Larry Bates a écrit :
(snip)
> def d(x):
> if isinstance(x, basestring):
> #
> # Code here for string
> #
> elif isinstance(x, int):
> #
> # Code here for int
> #
> elif isinstance(x, float):
> #
> # Code here for string
> #
> else:
> raise ValueError
As a side note : While there are a few corner cases where this is hardly
avoidable (and yet I'd rather test on interface, not on concrete type),
this kind of cose is exactly what OO polymorphic dispatch is supposed to
avoid (no, don't tell me: I know you can't easily add methods to most
builtin types).
More information about the Python-list
mailing list