no more comparisons

Alan Isaac aisaac at american.edu
Thu Mar 13 15:48:28 EDT 2008


>> Dan Bishop wrote:

>>> def cmp_key(cmp_fn):

>>>    class CmpWrapper(object):

>>>        def __init__(self, obj):

>>>            self.obj = obj

>>>        def __cmp__(self, other):

>>>            return cmp_fn(self.obj, other.obj)

>>>    return CmpWrapper







> On Mar 13, 12:38 pm, Alan Isaac  wrote:

>> how is this supposed to work if __cmp__ is no longer 

>> being called?  (Which was my understanding.)





Carl Banks wrote:

> It won't.  In Python 3.0 you'd have to write this class in terms of 

> rich comparisons (__lt__, __gt__, etc.). 





Exactly.  So something simple (define an anonymous function)

has become a bit of a pain.



On the other hand, I've looked through my extant code and

have not found a use of ``cmp`` that I cannot work around.

So maybe this is not as bad as I feared.  What are some use

cases that will clearly be harder (i.e., at least require

a slightly elaborate wrapper) after this change?



Cheers,

Alan Isaac





More information about the Python-list mailing list