Re: [Python-3000] Need closure on __cmp__ removal

2008-01-18 Thread Lars Immisch
Mike Klaas wrote: > On 18-Jan-08, at 1:37 PM, Lars Immisch wrote: >> >> 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

Re: [Python-3000] Need closure on __cmp__ removal

2008-01-18 Thread Mike Klaas
On 18-Jan-08, at 1:37 PM, Lars Immisch wrote: > > 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.""" >

Re: [Python-3000] Need closure on __cmp__ removal

2008-01-18 Thread Lars Immisch
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 so

Re: [Python-3000] Need closure on __cmp__ removal

2008-01-15 Thread David A. Wheeler
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 s

Re: [Python-3000] Need closure on __cmp__ removal

2008-01-09 Thread Mike Klaas
On 9-Jan-08, at 11:41 AM, Oleg Broytmann wrote: > On Wed, Jan 09, 2008 at 11:34:59AM -0800, Brett Cannon wrote: >> On Jan 9, 2008 11:34 AM, Oleg Broytmann <[EMAIL PROTECTED]> wrote: >>>newlist = oldlist.sort(key=lambda v: v.attr_x) >> >> And don't forget about operator.attrgetter(). > >I d

Re: [Python-3000] Need closure on __cmp__ removal

2008-01-09 Thread Oleg Broytmann
On Wed, Jan 09, 2008 at 11:34:59AM -0800, Brett Cannon wrote: > On Jan 9, 2008 11:34 AM, Oleg Broytmann <[EMAIL PROTECTED]> wrote: > >newlist = oldlist.sort(key=lambda v: v.attr_x) > > And don't forget about operator.attrgetter(). I don't like it for the task. To use I need to import opera

Re: [Python-3000] Need closure on __cmp__ removal

2008-01-09 Thread Brett Cannon
On Jan 9, 2008 11:34 AM, Oleg Broytmann <[EMAIL PROTECTED]> wrote: > On Wed, Jan 09, 2008 at 11:26:52AM -0800, Bill Janssen wrote: > > I'm a bit baffled here; I find cmp() fairly handy in writing sort > > routines: > > > >newlist = oldlist.sort(lambda v1, v2: cmp(v1.attr_x, v2.attr_x)) > > > >

Re: [Python-3000] Need closure on __cmp__ removal

2008-01-09 Thread Oleg Broytmann
On Wed, Jan 09, 2008 at 11:26:52AM -0800, Bill Janssen wrote: > I'm a bit baffled here; I find cmp() fairly handy in writing sort > routines: > >newlist = oldlist.sort(lambda v1, v2: cmp(v1.attr_x, v2.attr_x)) > > Is there a better / newer / official way of doing this? newlist = oldlist.s

Re: [Python-3000] Need closure on __cmp__ removal

2008-01-09 Thread Bill Janssen
Steve Bethard writes: > On Jan 8, 2008 3:55 PM, Brett Cannon <[EMAIL PROTECTED]> wrote: > > On Jan 8, 2008 2:41 PM, Guido van Rossum <[EMAIL PROTECTED]> wrote: > > > list.sort() and built-in sorted() are the least of our problems: even > > > though the API uses cmp, the implementation actually only

Re: [Python-3000] Need closure on __cmp__ removal

2008-01-09 Thread Guido van Rossum
On Jan 9, 2008 12:04 AM, Mark Summerfield <[EMAIL PROTECTED]> wrote: > I'm using this as a class decorator that fills in "missing" comparisons: > > def complete_comparisons(cls): > class CompleteComparisonsError(Exception): pass > > if hasattr(cls.__lt__, "__objclass__"): # i.e. < inherited

Re: [Python-3000] Need closure on __cmp__ removal

2008-01-09 Thread Marcin ‘Qrczak’ Kowalczyk
Dnia 09-01-2008, Śr o godzinie 01:49 +0100, Christian Heimes pisze: > You could write and implement a PEP about exposing the tp_richcompare > slot to Python code. How is it better than separate __eq__, __lt__ etc.? In most cases the rich comparison starts with dispatching on the operation and tre

Re: [Python-3000] Need closure on __cmp__ removal

2008-01-09 Thread Mark Summerfield
On 2008-01-09, Christian Heimes wrote: > Guido van Rossum wrote: > > That's a different issue altogether (and your wish is not likely going > > to be granted unless you write a PEP). > > You could write and implement a PEP about exposing the tp_richcompare > slot to Python code. > > import sys > >

Re: [Python-3000] Need closure on __cmp__ removal

2008-01-08 Thread Christian Heimes
Guido van Rossum wrote: > That's a different issue altogether (and your wish is not likely going > to be granted unless you write a PEP). You could write and implement a PEP about exposing the tp_richcompare slot to Python code. import sys class Example: def __richcmp__(self, other: object,

Re: [Python-3000] Need closure on __cmp__ removal

2008-01-08 Thread Guido van Rossum
That's a different issue altogether (and your wish is not likely going to be granted unless you write a PEP). On Jan 8, 2008 4:23 PM, hashcollision <[EMAIL PROTECTED]> wrote: > +1 from me too if you only need to define __lt__ and __eq__ and __le__ and > __gt__, etc, will default to that. If it dos

Re: [Python-3000] Need closure on __cmp__ removal

2008-01-08 Thread hashcollision
+1 from me too if you only need to define __lt__ and __eq__ and __le__ and __gt__, etc, will default to that. If it dosn't default to those, I feel that one would need to write too many functions. On Jan 8, 2008 7:12 PM, Steven Bethard <[EMAIL PROTECTED]> wrote: > On Jan 8, 2008 3:55 PM, Brett Ca

Re: [Python-3000] Need closure on __cmp__ removal

2008-01-08 Thread Steven Bethard
On Jan 8, 2008 3:55 PM, Brett Cannon <[EMAIL PROTECTED]> wrote: > On Jan 8, 2008 2:41 PM, Guido van Rossum <[EMAIL PROTECTED]> wrote: > > list.sort() and built-in sorted() are the least of our problems: even > > though the API uses cmp, the implementation actually only ever uses > > '<'; and the pr

Re: [Python-3000] Need closure on __cmp__ removal

2008-01-08 Thread Brett Cannon
On Jan 8, 2008 2:41 PM, Guido van Rossum <[EMAIL PROTECTED]> wrote: > list.sort() and built-in sorted() are the least of our problems: even > though the API uses cmp, the implementation actually only ever uses > '<'; and the preferred API is to use the 'key' argument instead of > passing a compare

Re: [Python-3000] Need closure on __cmp__ removal

2008-01-08 Thread Guido van Rossum
list.sort() and built-in sorted() are the least of our problems: even though the API uses cmp, the implementation actually only ever uses '<'; and the preferred API is to use the 'key' argument instead of passing a compare function; that's much more efficient. Maybe we should retire the compare fu

Re: [Python-3000] Need closure on __cmp__ removal

2008-01-08 Thread hashcollision
Ok, I do see your point, but how would one pass in a custom comparison function to sorted? On Jan 7, 2008 11:55 PM, Guido van Rossum <[EMAIL PROTECTED]> wrote: > On Jan 7, 2008 8:48 PM, hashcollision <[EMAIL PROTECTED]> wrote: > > > > > > > But the biggest thing missing is precise semantics. Say

Re: [Python-3000] Need closure on __cmp__ removal

2008-01-07 Thread Guido van Rossum
On Jan 7, 2008 8:48 PM, hashcollision <[EMAIL PROTECTED]> wrote: > > > > But the biggest thing missing is precise semantics. Saying "exactly > > the same semantics as with Python 2.5" doesn't cut it (those semantics > > are incredibly hairy and sometimes surprising, and their > > implementation was

Re: [Python-3000] Need closure on __cmp__ removal

2008-01-07 Thread hashcollision
> > But the biggest thing missing is precise semantics. Saying "exactly > the same semantics as with Python 2.5" doesn't cut it (those semantics > are incredibly hairy and sometimes surprising, and their > implementation was a nightmare -- I've rarely been as relieved as when > I was able to cut th

Re: [Python-3000] Need closure on __cmp__ removal

2008-01-06 Thread Guido van Rossum
On Jan 5, 2008 10:40 PM, hashcollision <[EMAIL PROTECTED]> wrote: > David A. Wheeler has already written a draft PEP, which can be found here: > http://www.dwheeler.com/misc/pep-cmp.txt. Thanks, I'd missed that. But alas, it's a bit short on the motivation for rich comparisons. For example it fai

Re: [Python-3000] Need closure on __cmp__ removal

2008-01-06 Thread hashcollision
David A. Wheeler has already written a draft PEP, which can be found here: http://www.dwheeler.com/misc/pep-cmp.txt. ___ Python-3000 mailing list Python-3000@python.org http://mail.python.org/mailman/listinfo/python-3000 Unsubscribe: http://mail.python.o

Re: [Python-3000] Need closure on __cmp__ removal

2008-01-04 Thread Adam Olsen
On Jan 4, 2008 12:18 PM, Guido van Rossum <[EMAIL PROTECTED]> wrote: > In the past some folks have been pushing for the resurrection of (some > form of) __cmp__, which is currently removed from Py3k (except for > some remnants which we'll clean up in due time). > > I'd like to get closure on this

[Python-3000] Need closure on __cmp__ removal

2008-01-04 Thread Guido van Rossum
In the past some folks have been pushing for the resurrection of (some form of) __cmp__, which is currently removed from Py3k (except for some remnants which we'll clean up in due time). I'd like to get closure on this issue. If someone volunteers within a week to write a PEP, I'll give them a mon