[Tutor] FW: isinstance -> instance
malaclypse2 at gmail.com
Mon Feb 26 23:07:56 CET 2007
On 2/26/07, Bernard Lebel <3dbernard at gmail.com> wrote:
> That's fine, but that tells me that 'a' is an instance of 'A'.
> It doesn't, however, tell me if 'a' is an instance or the actual class object.
>>> class A:
>>> a = A()
>>> isinstance(a, A)
>>> isinstance(A, A)
If you want to know if a is an instance of any type, try this:
>>> import types
>>> isinstance (a, types.InstanceType)
I'm pretty sure that types.InstanceType only works on old-style
classes. I believe you can check for an instance of a new-style class
More information about the Tutor