"Temporary" Variable

Steven D'Aprano steve at REMOVEMEcyber.com.au
Thu Feb 23 02:37:41 EST 2006


darthbob88 at gmail.com wrote:

> Problem: I wish to run an infinite loop and initialize a variable on
> each iteration. Sort of like, "Enter Data", test it, "No good!", "Next
> Try?", test it, etc. What I've tried is simply while 1: var1 =
> raw_input, test var1, then run through the loop again. What results is
> var1 gets and keeps the first value it receives. 

Hmmm. I get a syntax error.

 >>> while 1:
...     var1 = raw_input
...     test var1
   File "<stdin>", line 3
     test var1
             ^
SyntaxError: invalid syntax

How about posting your actual code?

You could try this:

while 1:
     var = raw_input("Give me some data! ")
     if var == "some data":
         print "Success!"
         break
     else:
         print "No good, try again."



-- 
Steven.




More information about the Python-list mailing list