Comparing 2 class types

Jürgen Hermann jhe at webde-ag.de
Fri Jul 7 12:58:09 EDT 2000


"Arinté" <shouldbe at message.com> schrieb im Newsbeitrag
news:L2k95.37383$NP5.1176274 at newsread2.prod.itd.earthlink.net...
> How can you know if a 2 variables are different instances of the same
class?
> x = someclass()
> y= someclass()
> I tried is, type, and type(x)  is someclass, but none seem to work unless
I
> did it wrong.

>>> class x: pass
...
>>> spam = x()
>>> eggs = x()
>>> spam
<__main__.x instance at 80bfa0>
>>> spam.__class__
<class __main__.x at 80b990>
>>> spam.__class__ is eggs.__class__
1
>>> isinstance(spam, eggs.__class__)
1






More information about the Python-list mailing list