Wesley Brooks wrote: > Dear Users, > > I'm in the process of adding assert statements to a large piece of > code to aid with bug hunting and came across the following issue; > > Using python in a terminal window you can do the following: > >> type(False) == bool > True > > I would like to check that an object is a class, here's an example: > >> class b: > ....def __init__(self): > ........self.c = 1 > ....def d(self): > ........print self.c > >> type(b) > <type 'classobj'> > > But the following fails: > >> type(b) == classobj > Traceback (most recent call last): > File "<stdin>", line 1, in ? > NameError: name 'classobj' is not defined
You can compare it against the ClassType object located in the types module. > import types > class b: ....def __init__(self): ........self.c = 1 ....def d(self): ........print self.c > type(b) == types.ClassType True -- Denis Kasak -- http://mail.python.org/mailman/listinfo/python-list