newbee I have an object how to check what's his class?

paul.keating at nibc.com paul.keating at nibc.com
Fri Nov 10 10:13:33 EST 2006


This doesn't answer your whole post because it asked a lot of
questions. But as to finding out whether something is an instance of a
class:

class X(object):
      # ... defined as in your post

>>> x = X('Fred')
>>> x
class X contains:
>>> type(x) is X
True
>>> isinstance(x,X)
True
>>> x.__class__.__name__
'X'

Now for subclasses:

class Y(X):
    extrastuffinY = 1

>>> y = Y('Joe')
>>> type(y) is X
False
>>> isinstance(y,X)
True


consternation:

> I can't find  neither in tutorial nor with google It's all about
> isinstance,  or  __class__.
> How to test that an object is an instance of my X class??




More information about the Python-list mailing list