|
From: Charlie G. <cha...@gm...> - 2007-08-30 07:16:26
|
On 8/29/07, dperez <cra...@ya...> wrote:
> If I run this code from the Jython 2.2 interactive console :
> 'a'.__cmp__('b')
> this is what happens:
> AttributeError: 'string' object has no attribute '__cmp__'
>
> This used to work in Jython 2.1.
>
> I don't understand what this happens, as the PyString class does have this
> method: __cmp__()
>
> Is this a bug?
Nope. Python added rich comparison methods(__eq__, __gt__, __le__ and
so on) in 2.1, and Jython's str uses those in 2.2 instead of __cmp__.
CPython exhibits the same behavior. You can get equivalent
functionality to __cmp__ with the builtin cmp function: cmp('a', 'b')
Charlie
|