[Python-Dev] python 3 niggle: None < 1 raises TypeError
ncoghlan at gmail.com
Tue Feb 18 23:27:03 CET 2014
On 19 Feb 2014 07:26, "Paul Moore" <p.f.moore at gmail.com> wrote:
> On 18 February 2014 21:17, Greg Ewing <greg.ewing at canterbury.ac.nz> wrote:
> > What I'd *really* like to be able to write is:
> > sort(invoices, keyattr = 'duedate', none = 'first')
> Which is of course a pretty trivial utility function to write. But I
> understand your point - these "trivial helpers" add up over time into
> a bit of a burden. But fixing that (if anyone feels it's worth doing
> so) can be handled many ways, and changing the semantics of None is
> far from the simplest or most obvious.
So perhaps the real answer is for someone to write a sorting helper module
and put it on PyPI. Things like sort_byattr (implicitly uses attrgetter),
sort_byitem (implicitly uses itemgetter), a flag argument defaulting to
"none_first=True", SortsLow and SortsHigh singletons, etc.
Those don't need to be builtins, but collating them into a clean helper API
would not only allow that module to be used directly, but also act as a
reference for anyone wanting to implement the behaviour themselves.
(I know, I know, we're way into python-ideas territory - it's just that so
much if the thread *was* on topic for python-dev, it seems relatively
pointless to split this iteration of the discussion. The *next* thread
about it should definitely be on python-ideas, though)
> Python-Dev mailing list
> Python-Dev at python.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-Dev