new-style class instance check

Richard Gruet rjgruet at yahoo.com
Sat Apr 10 19:11:16 EDT 2004


Hi all,

How to determine that an object o is for sure an instance of a new-style
class, without knowing of which specific class ?
That is, if I define a function:

def isNewStyleClassInstance(o):
    pass    ## to be completed

.. I want to pass the following test:

def C: pass
def CNew(object): pass

assert not isNewStyleClassInstance(C()) # InstanceType
assert isNewStyleClassInstance(CNew())
assert not isNewStyleClassInstance(1)    # instance of type int
# and naturally for all other types of o the function should return False.

Richard





More information about the Python-list mailing list