[Python-3000] Need closure on __cmp__ removal
lars at ibp.de
Fri Jan 18 22:37:25 CET 2008
David A. Wheeler wrote:
> Bill Janssen:
>> I'm a bit baffled here; I find cmp() fairly handy in writing sort routines...
>> Is there a better / newer / official way of doing this? If not, isn't
>> "cmp()" still useful to have around?
> I agree with you - I find cmp() useful, and I notice that some others do too.
> E.G., Adam Olson said "It's clear to me that the opposition to
> removing __cmp__ comes down to "make the common things easy and
> the rare things possible". Removing __cmp__ means one of the
> common things (total ordering) becomes hard."
I like cmp, too. I've looked through my code, and I've only used it in
script-ish circumstances, but here is an example that sorts a list of
files by modification date:
def cmp_mtime(f, g):
"""Too much for a lambda for my tastes."""
return cmp(os.stat(f).st_mtime, os.stat(g).st_mtime)
files = os.listdir('.')
More information about the Python-3000