while (assignment):
Peter Abel
p-abel at t-online.de
Tue Jul 29 17:00:56 EDT 2003
Sybren Stuvel <sybrenUSE at YOURthirdtower.imagination.com> wrote in message news:<slrnbicopb.6gh.sybrenUSE at sybren.thirdtower.com>...
> Hi there,
>
> Is it possible to use an assignment in a while-loop? I'd like to do
No I guess.
This is typical C, to use an assignment and work with its result
in the same statement.
One famous representative is the following which is the reason
for many faults:
if (a=somethting)
{
...
}
what means in pyhton:
a=something
if a:
...
> something like "loop while there is still something to be read, and if
> there is, put it in this variable". I've been a C programmer since I
> was 14, so a construct like:
>
> while info = mydbcursor.fetchone():
> print "Information: "+str(info)
>
The following should work:
info = mydbcursor.fetchone()
while info:
print "Information: "+str(info)
info = mydbcursor.fetchone()
> comes to mind. Unfortunately, this doesn't work. Is there a similar
> construct in python?
>
> Sybren
Regards
Peter
More information about the Python-list
mailing list