int rich comparisons
Terry Reedy
tjreedy at udel.edu
Fri Oct 2 21:51:02 EDT 2009
Robert Kern wrote:
> George Sakkis wrote:
>> I stumbled upon the following strangeness (python 2.6.2):
>>
>>>>> getattr(int, '__gt__')
>> <method-wrapper '__gt__' of type object at 0x822b7c0>
>>
>>>>> getattr(5, '__gt__')
>> Traceback (most recent call last):n
>> File "<stdin>", line 1, in <module>
>> AttributeError: 'int' object has no attribute '__gt__'
>>
>> Is this a bug ?
>
> I believe that ints in the 2.x series still use __cmp__. In Python 3.x,
> __gt__ and the rest are defined.
Correct:
Python 3.1 (r31:73574, Jun 26 2009, 20:21:35) [MSC v.1500 32 bit
(Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> 5 .__gt__ # notice space after 5
<method-wrapper '__gt__' of int object at 0x1E1FC058>
More information about the Python-list
mailing list