how to find out if an object is a class?
Terry Reedy
tjreedy at udel.edu
Thu Aug 7 20:56:56 EDT 2008
Wojtek Walczak wrote:
> Dnia Thu, 7 Aug 2008 14:36:37 -0700 (PDT), szczepiq napisa�(a):
>> Pardon me for most likely a dummy question but how do I find out if an
>> object is a class?
>
>
> Use types.ClassType:
>
>>>> class Q:
> ... pass
> ...
>>>> import types
>>>> isinstance(Q, types.ClassType)
>>>> True
That is only true and only works for 2.x old-style classes and not for
2.x new-style classes and all 3.0 classes, for which isinstance(Q,type)
is True.
>>> class old: pass
...
>>> type(old)
<type 'classobj'>
>>> class new(object): pass
...
>>> type(new)
<type 'type'>
More information about the Python-list
mailing list