sufficiently pythonic code for testing type of function

Theerasak Photha hanumizzle at gmail.com
Wed Oct 11 04:37:48 EDT 2006


On 10/11/06, Bruno Desthuilliers <onurb at xiludom.gro> wrote:

> Now the real question : what if the object is not an instance of any of
> the types, but still support the expected interface ?

Perhaps:

try:
  for attribute in ['foo', 'bar', '__baz__']:
    getattr(mystery_object, '__%s__' % attribute)
except AttributeError:
  # Do sumthin bout it

Is it wrong to 're-raise' an exception with application-specific
details within an except clause?

-- Theerasak



More information about the Python-list mailing list