[Python-3000] Warning for 2.6 and greater

Aahz aahz at pythoncraft.com
Wed Jan 10 16:39:45 CET 2007


On Tue, Jan 09, 2007, Thomas Wouters wrote:
> On 1/9/07, Aahz <aahz at pythoncraft.com> wrote:
>> 
>>Hey!  What's this about __cmp__?!
> 
> Python 3.0x (p3yk:53295, Jan  8 2007, 09:32:17)
> [GCC 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
> >>>object.__cmp__
> Traceback (most recent call last):
>  File "<stdin>", line 1, in <module>
> AttributeError: type object 'object' has no attribute '__cmp__'
> 
> E's dead. Stone dead, miss.

Unfortunately, I haven't set up a checkout of py3k yet, could you please
test what this does:

    class CheapCompare:
        def __init__(self, value):
            self.value = value
        def __cmp__(self, other):
            x = self.value
            y = other.value
            if x == y:
                return 0
            elif x > y:
                return 1
            else:
                return -1

    print cmp(CheapCompare(1), CheapCompare(2))

If that doesn't work, I expect there to be some unhappy Numeric people.
OTOH, if that does work, what exactly will you be warning about?
-- 
Aahz (aahz at pythoncraft.com)           <*>         http://www.pythoncraft.com/

"Plus ca change, plus c'est la meme chose."


More information about the Python-3000 mailing list