Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #102285 > unrolled thread

Re: Cannot step through asynchronous iterator manually

Started byChris Angelico <rosuav@gmail.com>
First post2016-01-30 19:09 +1100
Last post2016-01-30 19:09 +1100
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Cannot step through asynchronous iterator manually Chris Angelico <rosuav@gmail.com> - 2016-01-30 19:09 +1100

#102285 — Re: Cannot step through asynchronous iterator manually

FromChris Angelico <rosuav@gmail.com>
Date2016-01-30 19:09 +1100
SubjectRe: Cannot step through asynchronous iterator manually
Message-ID<mailman.115.1454141369.2338.python-list@python.org>
On Sat, Jan 30, 2016 at 7:02 PM, Ian Kelly <ian.g.kelly@gmail.com> wrote:
> On Jan 29, 2016 11:04 PM, "Frank Millman" <frank@chagford.com> wrote:
>>
>> Hi all
>>
>> To loop though an iterator one usually uses a higher-level construct such
> as a 'for' loop. However, if you want to step through it manually you can
> do so with next(iter).
>>
>> I expected the same functionality with the new 'asynchronous iterator' in
> Python 3.5, but I cannot find it.
>>
>> I can achieve the desired result by calling 'await aiter.__anext__()',
> but this is clunky.
>>
>> Am I missing something?
>
> async for x in aiter:
>     pass

Yeah, he wants to single-step it. A regular for loop is equivalent to
calling next() lots of times, and you can manually call next(). Common
usage: Skip a header row before iterating over the rest of a file. So
how do you do the same thing with an async iterator? I'm not sure
there's a way, currently. That's the question.

Of course, you can always do this:

async for x in aiter: break

as an equivalent to "x = next(aiter)", but that's just stupid :)

ChrisA

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web