Documentation, assignment in expression.

mwilson at the-wire.com mwilson at the-wire.com
Mon Mar 26 07:27:15 EDT 2012


Dennis Lee Bieber wrote:

> On Sun, 25 Mar 2012 19:09:12 -0400, mwilson at the-wire.com declaimed the
> following in gmane.comp.python.general:
> 
> 
>> Most of my database programs wind up having the boilerplate (not tested):
>> 
>> def rowsof (cursor):
>>     names = [x[0] for x in cursor.description]
>>     r = cursor.fetchone()
>>     while r:
>>         yield dict (zip (names, r))
>>         r = cursor.fetchone()
>>
> 
> In my (limited) experience, the main loop above could be replaced
> with:
> 
> for r in cursor:
> yield dict(zip(names, r))

I think your experience is more recent than mine.  I'll change my 
boilerplate next time around.

	Mel.




More information about the Python-list mailing list