testing for class of instance

Greg Ball greg.ball at earthling.net
Sun May 13 10:57:54 EDT 2001


Stephen Hansen <news at mynospam.org> wrote:

> def printname(object):
>     try:
>         print 'My name is ', object[name]
>     except TypeError, AttributeError:
>         print 'You didn't send me a dictionary-like object!'


You mean 

      except (TypeError,AttributeError):
               ...

As written, you will catch only TypeError, and when
you do, you'll assign the exception to local variable
AttributeError.

See  http://www.amk.ca/python/writing/warts.html

--Greg Ball




More information about the Python-list mailing list