Michele Simionato wrote:
> [EMAIL PROTECTED] wrote:
>> I need to find out if an object is a class.
>> Which is quite simply awful...does anyone know of a better way to do
>> this?
> 
> inspect.isclass
> 
>      M.S.
> 
...which made me wonder what this canonical test is.  The answer:

def isclass(object):
     """Return true if the object is a class.

     Class objects provide these attributes:
         __doc__         documentation string
         __module__      name of module in which this class was defined"""
     return isinstance(object, types.ClassType) or hasattr(object, '__bases__')

I wonder why the test isn't

     isinstance(object, (types.ClassType, type))

Michael

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to