Movatterモバイル変換


[0]ホーム

URL:


[Python-Dev] PEP 309: Partial method application

Steven Bethardsteven.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).[snip]> 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 toitemgetter and attrgetter.  Of course, when Python 2.5 comes out, it'scertainly possible that the multi-argument forms will becomecommonplace.I agree that an operator.methodcaller() shouldn't try to supportmultiple methods.  OTOH, the syntax    methodcall.method(*args, **kwargs)doesn't really lend itself to multiple methods either.STeVe-- You can wordify anything if you just verb it.        --- Bucky Katt, Get Fuzzy


More information about the Python-Devmailing list

[8]ページ先頭

©2009-2025 Movatter.jp