Re: while (assignment):

Discussion in 'Python' started by Sybren Stuvel, Jul 30, 2003.

  1. 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?
     
    Sybren Stuvel, Jul 30, 2003
    #1
    1. Advertising

  2. Sybren Stuvel <> wrote in message news:<>...
    > 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
     
    Michele Simionato, Jul 30, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Sybren Stuvel

    variable assignment in "while" loop

    Sybren Stuvel, Jul 29, 2003, in forum: Python
    Replies:
    6
    Views:
    423
    Bengt Richter
    Jul 29, 2003
  2. Andy Todd
    Replies:
    0
    Views:
    802
    Andy Todd
    Jul 29, 2003
  3. Andy Todd
    Replies:
    1
    Views:
    391
    Raymond Hettinger
    Jul 30, 2003
  4. nagy
    Replies:
    36
    Views:
    1,014
    Terry Reedy
    Jul 20, 2006
  5. Chris
    Replies:
    34
    Views:
    1,529
Loading...

Share This Page