Jython class names

Robin Becker robin at jessikat.fsnet.co.uk
Tue Sep 9 08:00:15 EDT 2003


In article <bjk2fk$38o$07$1 at news.t-online.com>, Peter Otten
<__peter__ at web.de> writes
>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:
>

I just tried and wow


>>>> class C: pass
>...
>>>> C().__class__.__name__ is C.__name__
>True

it doesn't work

C:\jython-2.1>jython
Jython 2.1 on java1.4.2 (JIT: null)
Type "copyright", "credits" or "license" for more information.
>>> class C: pass
...
>>> C().__class__.__name__ is C.__name__
0
>>> C().__class__.__name__ == C.__name__
1
>>>



......
>
>(Of course isinstance() will also return True for subclass instances)
>
>Peter
We're using the name tests in case we get the class from different
import paths.
-- 
Robin Becker




More information about the Python-list mailing list