[Python-Dev] PEP 309: Partial method application

Steven Bethard steven.bethard at gmail.com
Fri Aug 19 09:14:17 CEST 2005

Martin v. Löwis wrote:
> Steven Bethard wrote:
> >>I thought that:
> >>  operator.attrgetter() was for obj.attr
> >>  operator.itemgetter() was for obj[integer_index]
> >
> >
> > My point exactly.  If we're sticking to the same style, I would expect that for
> >     obj.method(*args, **kwargs)
> > we would have something like:
> >     operator.methodcaller('method', *args, **kwargs)
> You might be missing one aspect of attrgetter, though. I can have
>   f = operator.attrgetter('name', 'age')
> and then f(person) gives me (person.name, person.age). Likewise for
> itemgetter(1,2,3).
> I don't know what the common use for
> attrgetter is: one or more attributes?

Well, in current Python code, I'd be willing to wager that it's one,
no more, since Python 2.4 only supports a single argument to
itemgetter and attrgetter.  Of course, when Python 2.5 comes out, it's
certainly possible that the multi-argument forms will become

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.

You can wordify anything if you just verb it.
        --- Bucky Katt, Get Fuzzy

More information about the Python-Dev mailing list