[Fwd: while row = c.fetchone(): # syntax error???]
Just van Rossum
just at letterror.com
Fri Aug 11 08:06:14 EDT 2000
Pablo Prieto wrote:
>
> > into the equivalent Python idiom:
> >
> > while 1:
> > row=c.fetchone()
> > if not row: break
> > doit(row)
> >
> > Alternatives abound, e.g:
> >
> > class valueWrapper:
> > def set(self,value):
> > self.value=value
> > return value
> >
> > row=valueWrapper()
> >
> > while row.set(c.fetchone()):
> > doit(row.value)
> >
> > Alex
>
> How I do it:
>
> t = c.fetchone()
> while t
> --- # Very intelligent code goes here :)
> t = c.fetchone()
And now for the "official" Python idiom, which avoids duplication of the
t = c.fetchone() line:
while 1:
t = c.fetchone()
if not t:
break
--- # Very intelligent code goes here :)
Just
More information about the Python-list
mailing list