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. Advertisements

  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. Advertisements

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. ^CrazyCoder^
    Replies:
    3
    Views:
    7,698
    Terrence Benade
    Sep 15, 2003
  2. Sybren Stuvel

    variable assignment in "while" loop

    Sybren Stuvel, Jul 29, 2003, in forum: Python
    Replies:
    6
    Views:
    614
    Bengt Richter
    Jul 29, 2003
  3. Andy Todd
    Replies:
    1
    Views:
    496
    Raymond Hettinger
    Jul 30, 2003
  4. John Roth

    Re: while (assignment):

    John Roth, Jul 30, 2003, in forum: Python
    Replies:
    2
    Views:
    374
    Sybren Stuvel
    Jul 30, 2003
  5. none

    Assignment in a while?

    none, Apr 2, 2006, in forum: Python
    Replies:
    9
    Views:
    568
    Alex Martelli
    Apr 3, 2006
  6. nagy
    Replies:
    36
    Views:
    1,480
    Terry Reedy
    Jul 20, 2006
  7. Alex Vinokur
    Replies:
    13
    Views:
    603
    Aleksey Loginov
    Oct 26, 2005
  8. Chris
    Replies:
    34
    Views:
    2,419
Loading...