A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2012-November/122866.html below:

[Python-Dev] operator.attrgetter(attr[, args...]) etc.

[Python-Dev] operator.attrgetter(attr[, args...]) etc.Oscar Benjamin oscar.j.benjamin at gmail.com
Wed Nov 21 15:49:05 CET 2012
On 21 November 2012 03:57, Leo <sdl.web at gmail.com> wrote:
> Sorry the python issue tracker seems broken (I cannot log in). So I am
> posting it here.
>
> In the doc:
>
>   operator.attrgetter(attr[, args...])
>   operator.itemgetter(item[, args...])
>   operator.methodcaller(name[, args...])
>
> The signatures of these functions seem confusing. ARGS is not documented
> and does not match the python implementation in the doc.

What documentation are you reading?

$ python
Python 2.7.1 (r271:86832, Nov 27 2010, 18:30:46) [MSC v.1500 32 bit
(Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import operator
>>> help(operator.attrgetter)
Help on class attrgetter in module operator:

class attrgetter(__builtin__.object)
 |  attrgetter(attr, ...) --> attrgetter object
 |
 |  Return a callable object that fetches the given attribute(s) from
its operand.
 |  After, f=attrgetter('name'), the call f(r) returns r.name.
 |  After, g=attrgetter('name', 'date'), the call g(r) returns (r.name, r.date).
 |  After, h=attrgetter('name.first', 'name.last'), the call h(r) returns
 |  (r.name.first, r.name.last).
[snip]

I think the above explains how attrgetter works with multiple
arguments. Here's a demo:

>>> class X:
...     a = 2
...     b = 3
...     c = 1
...
>>> getter = operator.attrgetter('a', 'b', 'c')
>>> getter(X)
(2, 3, 1)


Oscar
More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4