Documentation, assignment in expression.

Thomas Rachel nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de
Mon Mar 26 15:59:08 CEST 2012


Am 25.03.2012 15:03 schrieb Tim Chase:
> Perhaps a DB example
> works better. With assignment allowed in an evaluation, you'd be able to
> write
>
> while data = conn.fetchmany():
>     for row in data:
>         process(row)
>
> whereas you have to write
>
> while True:
>     data = conn.fetchmany()
>     if not data: break
>     for row in data:
>         process(row)

Or simpler

for data in iter(conn.fetchmany, []):
     for row in data:
         process(row)

provided that a block of rows is returned as a list - which might be 
different among DB engines.


Thomas



More information about the Python-list mailing list