Jython class names

Peter Otten __peter__ at web.de
Tue Sep 9 10:19:59 CEST 2003

Robin Becker wrote:

> I recently came across a problem with porting to Jython
> basically the following is prints 1 in CPython, but not in Jython.
> class C:
>         pass
> red = C()
> print red.__class__.__name__ is 'C'
> it seems that Jython doesn't intern names in the same way or instances
> are not constructed in the same way. Is the above test robust or should
> I always be using == for testing class names?

I have no Jython around, but I expect the following to always work:

>>> class C: pass
>>> C().__class__.__name__ is C.__name__
>>> isinstance(C(), C)

(Of course isinstance() will also return True for subclass instances)


More information about the Python-list mailing list