At Wednesday 3/1/2007 13:57, Wesley Brooks wrote:
>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
Do you want to test if you got a `b` class, or just for any class?
See inspect.isclass for the latter.
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?
Usually, Python code doesn't care if you pass the exact class
designed. If a function writes some text to a file that it gets as an
argument, it doesn't care whether it gets a file object or some other
kind of object, as far as it has a suitable write() method.
If you positively have to check for the class, checking types with ==
is not a good idea. Use isinstance or issubclass instead, they check
for derived classes too. A derived class can (or could) always be
used wherever a base class is suitable.
--
Gabriel Genellina
Softlab SRL
__________________________________________________
Preguntá. Respondé. Descubrí.
Todo lo que querías saber, y lo que ni imaginabas,
está en Yahoo! Respuestas (Beta).
¡Probalo ya!
http://www.yahoo.com.ar/respuestas
--
http://mail.python.org/mailman/listinfo/python-list