[Python-ideas] Integrate some itertools into the Python syntax

Michel Desmoulin desmoulinmichel at gmail.com
Tue Mar 22 17:47:19 EDT 2016



Le 22/03/2016 21:17, Ethan Furman a écrit :
> On 03/22/2016 12:43 PM, Michel Desmoulin wrote:
>> No you didn't store the lines, the whole points is that they are
>> returning generators.
>>
>> In that context, f[begin, end] does itertools.takewhile and
>> dropwhile and [:10000] is doing islice(0, 10000). None of those
>> functions store anything.
>>
>> Please read the begining of thread.
> 
> I presume you are referring to this line:
> 
>> The slicing would then return a list if it's a list, a tuple if it's
>> a tuple, and a islice(generator) if it's a generator.
> 
> Of which the big problem is that the object returned from an open call
> is not a list, not a tuple, and not a generator.
> 
> For the sake of argument let's pretend you meant "and an islice(iter)
> for everything else".
> 
> So the actual proposal is to add `__getitem__` to `object` (that way all
> classes that define their own `__getitem__` such as list and tuple are
> not affected), and the substance of this new `__getitem__` is to:
> 
> - check for an `__iter__` method (if none, raise TypeError)
> - check the start, stop, step arguments to determine whether
>   dropwhile, takewhile, or islice is needed
> - return the appropriate object
> 
> Okay, it's an interesting proposal.
> 
> I would suggest you make the changes, run the test suite, see if
> anything blows up.

I have literally no idea where to start. I hope this doesn't require
editing the C source code because I don't know C.

> 
> As a short-cut maybe you could add the code to the appropriate ABC and
> test that way.
> 
> -- 
> ~Ethan~
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/


More information about the Python-ideas mailing list