Proposed new syntax

Chris Angelico rosuav at gmail.com
Thu Aug 24 07:33:38 EDT 2017


On Thu, Aug 24, 2017 at 8:40 PM, Ben Finney <ben+python at benfinney.id.au> wrote:
> Paul Rubin <no.email at nospam.invalid> writes:
>
>> Ben Finney <ben+python at benfinney.id.au> writes:
>> >     generate_id = functools.partial(next, itertools.count())
>>
>> Is something wrong with:
>>
>>     >>> g = itertools.count().next
>
> I wasn't looking for a ‘next’ method on the iterator. Is that special to
> the ‘itertools.count’ type?
>
> If so, I was attempting to give the more general solution to “how do I
> get a function that will give me the next thing from this iterator”.

It's on all iterators; it's the Py2 equivalent for __next__. When you
call next(x), Py2 calls x.next(), which - being an inconsistent name -
got renamed to the more appropriate __next__() in Py3.

ChrisA



More information about the Python-list mailing list