type classobj not defined?

"Martin v. Löwis" martin at v.loewis.de
Wed Jan 3 14:08:58 EST 2007


Wesley Brooks schrieb:
>> type(b) == classobj
> Traceback (most recent call last):
>  File "<stdin>", line 1, in ?
> NameError: name 'classobj' is not defined
> 
> For the time being I'll use b.__name__ == b to ensure I'm getting the
> right class. Is there a reason why the other types such as bool are
> defined but classobj isn't?

In general, only those types which you also use as constructors are
builtin. I.e. you would write bool(foo) (where foo is a variable),
but you would not write classobj("bar") (to create a class named
"bar"). That you can also use it for a type test is a side-effect.

Some more types are available in the types module. In this case,
you can use types. In this case, types.ClassType would do the trick.

Regards,
Martin



More information about the Python-list mailing list