int rich comparisons

G

George Sakkis

I stumbled upon the following strangeness (python 2.6.2):
Traceback (most recent call last):n
File "<stdin>", line 1, in <module>
AttributeError: 'int' object has no attribute '__gt__'

Is this a bug ?

George
 
M

Mark Dickinson

I stumbled upon the following strangeness (python 2.6.2):


Traceback (most recent call last):n
  File "<stdin>", line 1, in <module>
AttributeError: 'int' object has no attribute '__gt__'

Is this a bug ?

I don't think so. Notice that in the first example you're picking
up the __gt__ method of the *type* object, not the int object; i.e.,
the method that's executed when you do:
True

You get similar results with __call__:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'int' object has no attribute '__call__'

Mark
 
R

Robert Kern

George said:
I stumbled upon the following strangeness (python 2.6.2):

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.

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco
 
T

Terry Reedy

Robert said:
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.<method-wrapper '__gt__' of int object at 0x1E1FC058>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,077
Latest member
SangMoor21

Latest Threads

Top