diff options
Diffstat (limited to 'Doc/library/operator.rst')
-rw-r--r-- | Doc/library/operator.rst | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/Doc/library/operator.rst b/Doc/library/operator.rst index 9a613ab..ca056ab 100644 --- a/Doc/library/operator.rst +++ b/Doc/library/operator.rst @@ -419,10 +419,12 @@ expect a function argument. Return a callable object that fetches *attr* from its operand. If more than one attribute is requested, returns a tuple of attributes. After, - ``f=attrgetter('name')``, the call ``f(b)`` returns ``b.name``. After, - ``f=attrgetter('name', 'date')``, the call ``f(b)`` returns ``(b.name, + ``f = attrgetter('name')``, the call ``f(b)`` returns ``b.name``. After, + ``f = attrgetter('name', 'date')``, the call ``f(b)`` returns ``(b.name, b.date)``. + The attribute names can also contain dots; after ``f = attrgetter('date.month')``, + the call ``f(b)`` returns ``b.date.month``. .. function:: itemgetter(item[, args...]) @@ -443,6 +445,15 @@ Examples:: [('orange', 1), ('banana', 2), ('apple', 3), ('pear', 5)] +.. function:: methodcaller(name[, args...]) + + Return a callable object that calls the method *name* on its operand. If + additional arguments and/or keyword arguments are given, they will be given + to the method as well. After ``f = methodcaller('name')``, the call ``f(b)`` + returns ``b.name()``. After ``f = methodcaller('name', 'foo', bar=1)``, the + call ``f(b)`` returns ``b.name('foo', bar=1)``. + + .. _operator-map: Mapping Operators to Functions |