[Python-Dev] PEP 309: Partial method application

"Martin v. Löwis" martin at v.loewis.de
Thu Aug 18 21:40:19 CEST 2005

Ian Bicking wrote:
>      lst = ['A', 'b', 'C']
>      lst.sort(key=partialmethod('lower'))
> Which sorts by lower-case.  Of course you can use str.lower, except 
> you'll have unnecessarily enforced a type (and excluded Unicode).  So 
> you are left with lambda x: x.lower().

For this specific case, you can use string.lower (which is exactly
what the lambda function does).

As for the more general proposal: -1 on more places to pass strings to
denote method/function/class names. These are ugly to type.

What I think you want is not a partial method, instead, you want to
turn a method into a standard function, and in a 'virtual' way.

So I would propose the syntax

  lst.sort(key=virtual.lower) # where virtual is functional.virtual

As for extending PEP 309: This PEP deliberately abstained from other
ways of currying, and instead only introduced the functional module.
If you want to see "lazy functions" in the standard library, you should
write a new PEP (unless there is an easy agreement about a single right
way to do this, which I don't see).


P.S. It's not even clear that this should be added to functional,
as attrgetter and itemgetter are already in operator. But, perhaps,
they should be in functional.

More information about the Python-Dev mailing list