Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: while (assignment):

Reply
Thread Tools

Re: while (assignment):

 
 
Sybren Stuvel
Guest
Posts: n/a
 
      07-30-2003
Hannu Kankaanpää enlightened us with:
> Typically this is done by breaking out of the loop:
>
> while True:
> info = mydbcursor.fetchone()
> if not info:
> break
> print "Information: "+str(info)


This was my first solution as well. Kinda ugly, though.

Sybren
--
The problem with the world is stupidity. Not saying there should be a
capital punishment for stupidity, but why don't we just take the
safety labels off of everything and let the problem solve itself?
 
Reply With Quote
 
 
 
 
Michele Simionato
Guest
Posts: n/a
 
      07-30-2003
Sybren Stuvel <(E-Mail Removed)> wrote in message news:<(E-Mail Removed) om>...
> Hannu Kankaanpää enlightened us with:
> > Typically this is done by breaking out of the loop:
> >
> > while True:
> > info = mydbcursor.fetchone()
> > if not info:
> > break
> > print "Information: "+str(info)

>
> This was my first solution as well. Kinda ugly, though.
>
> Sybren


When I started using Python I though the "while 1" idiom was horrible.
Now I think it is quite Pythonic. Few months can change your mind!

You may also use this form, which you may find more readable:

while 'info':
info = mydbcursor.fetchone()
if not info: break
print "Information: "+str(info)

Remember, 'info' is another spelling of True!
This is a trick anyway, and I always use "while 1" in my code, it is
the idiomatic way at the end.

Michele
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
While deploying application on AIX I got this error. while it's working fine on windows Sam Java 0 06-21-2006 06:26 AM
while loop in a while loop Steven Java 5 03-30-2005 09:19 PM
while 1 vs while True Timothy Fitz Python 16 12-15-2004 09:27 PM
Help while error "Error while trying to run project:" David ASP .Net 1 07-19-2004 08:41 PM
Got error msg while Debugging : Error while trying to run project: ... ^CrazyCoder^ ASP .Net 3 09-15-2003 09:40 AM



Advertisments