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). Extending this to methodcaller is not natural; you would have x=methodcaller(('open',['foo','r'],{}),('read',[100],{}), ('close',[],{})) and then x(somestorage) (I know this is not the typical open/read/close pattern, where you would normally call read on what open returns) It might be that there is no use case for a multi-call methodgetter; I just point out that a single-call methodgetter would *not* be in the same style as attrgetter and itemgetter. > attrget.attr (for obj.attr) > itemget[key] (for obj[key]) I agree that would be consistent. These also wouldn't allow to get multiple items and indices. I don't know what the common use for attrgetter is: one or more attributes? Regards, Martin _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com