Cannot step through asynchronous iterator manually

Frank Millman frank at chagford.com
Sat Jan 30 07:39:44 EST 2016


"Maxime S"  wrote in message 
news:CAGqiJR8yUdd1u7j0YHS-He_v4uUT-ui=PpiX=n_G=ntt8ZnTpg at mail.gmail.com...

>
> I might be a bit off-topic, but why don't you simply use cursor.rowcount?
>

I just tried that on sqlite3 and pyodbc, and they both return -1.

I think that it only works with insert/update/delete, but not with select.

> For a pure iterator-based solution, I would do something like this 
> (admitly
> a bit cryptic, but iterator-based solutions often are :-) :
>
> async def get_uniqu(ait):
>     async for row in ait:
>         break
>     else:
>         raise NotEnoughtRows()
>     async for _ in ait:
>         raise TooManyRows()
>     return row
>

Also nice - thanks. I now have a few to choose from without needing an 
'anext()'.

Frank





More information about the Python-list mailing list