J
John Nagle
I want to test whether an object is an instance of any user-defined
class. "isinstance" is less helpful than one would expect.
.... pass
....<__main__.foo instance at 0x020080A8>
So far, so good. x is an InstanceType. But let's try a
class with a constructor:
.... def __init__(self, val) :
.... self.val = val
....<class '__main__.bar'>
Without a constructor, we get an "instance". With a constructor,
we get an "object", one which is not an InstanceType.
One might think that testing for types.ObjectType would help. But
no, everything is an ObjectType:
True
So that's useless.
I have to be missing something obvious here.
(CPython 2.6)
John Nagle
class. "isinstance" is less helpful than one would expect.
.... pass
....<__main__.foo instance at 0x020080A8>
So far, so good. x is an InstanceType. But let's try a
class with a constructor:
.... def __init__(self, val) :
.... self.val = val
....<class '__main__.bar'>
Without a constructor, we get an "instance". With a constructor,
we get an "object", one which is not an InstanceType.
One might think that testing for types.ObjectType would help. But
no, everything is an ObjectType:
True
So that's useless.
I have to be missing something obvious here.
(CPython 2.6)
John Nagle