Easy Q: dealing with object type
Daniel Bickett
dbickett at gmail.com
Wed Feb 2 21:05:23 EST 2005
On Erik Johnson wrote:
> # The following "works", but I don't want to keep a set of instances to
> compare against
> >>> obj2 = A()
> >>> type(obj) == type(obj2)
> 1
How about:
>>> class A:
pass
>>> class B:
pass
>>> objA = A()
>>> type( objA ) == type( A() )
True
then again....
>>> objB = B()
>>> type( objA ) == type( B() )
True
they're both of type 'instance'. So how about this:
>>> class A:
pass
>>> class B( object ):
pass
>>> objA = A()
>>> objB = B()
>>> type( objA )
<type 'instance'>
>>> type( objB )
<class '__main__.B'>
>>> type( objB ) == B
True
I believe that achieves what you were aiming for.
--
Daniel Bickett
dbickett at gmail.com
http://heureusement.org/
More information about the Python-list
mailing list