[Python-Dev] PEP 309: Partial method application

Raymond Hettinger raymond.hettinger at verizon.net
Fri Aug 19 18:39:18 CEST 2005


[Steven Bethard]
> > I agree that an operator.methodcaller() shouldn't try to support
> > multiple methods.  OTOH, the syntax
> >     methodcall.method(*args, **kwargs)
> > doesn't really lend itself to multiple methods either.

[Josiah Carlson]
> But that's OK, we don't want to be calling multiple methods anyways,
do
> we?  I'd personally like to see an example it makes sense if someone
> says that we do.

If an obvious syntax doesn't emerge, don't fret.  The most obvious
approach is to define a regular Python function and supply that function
to the key= argument for list.sort() or sorted().

A virtue of the key= argument was reducing O(n log n) calls to just
O(n).  Further speed-ups are a false economy.  So there's no need to
twist syntax into knots just to get a C based method calling function.

Likewise with map(), if a new function doesn't fit neatly, take that as
a cue to be writing a plain for-loop.


Raymond



More information about the Python-Dev mailing list