[Tutor] FW: isinstance -> instance
Jerry Hill
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.
It doesn't?
>>> class A:
pass
>>> a = A()
>>> isinstance(a, A)
True
>>> isinstance(A, A)
False
If you want to know if a is an instance of any type, try this:
>>> import types
>>> isinstance (a, types.InstanceType)
True
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
with:
isinstance(a, object)
--
Jerry
More information about the Tutor
mailing list