itemgetter with default arguments

Ian Kelly ian.g.kelly at gmail.com
Sat May 5 10:17:42 EDT 2018


On Fri, May 4, 2018 at 5:34 PM, Thomas Jollans <tjol at tjol.eu> wrote:
> On 04/05/18 22:38, Ian Kelly wrote:
>> The real thing is written in C.
>>
>
> Is it though?
>
> https://github.com/python/cpython/blob/a1fc949b5ab8911a803eee691e6eea55cec43eeb/Lib/operator.py#L265

It is. First, notice the docstring of that module says, "This is the
pure Python implementation of the module." Second, notice that near
the bottom of the file is this code:

try:
    from _operator import *
except ImportError:
    pass
else:
    from _operator import __doc__

The implementation actually used by CPython is here:

https://github.com/python/cpython/blob/a1fc949b5ab8911a803eee691e6eea55cec43eeb/Modules/_operator.c#L402

The pure Python version exists to be shared by other Python
implementations that don't support C extensions.



More information about the Python-list mailing list