Discussion:
[Tutor] changing a variable with raw_input
richard kappler
2015-09-16 17:03:04 UTC
Permalink
Missing something obvious here, but down with the flu so I'm foggy and just
can't see it. I need to set a variable 'delay' to be used in
time.sleep(delay) later on in a script, based on user input. Something odd
is going on in setting the variable though. Here's the snippet where I'm
trying to set the variable:

#!/usr/bin/env python

delay = 7

print("1 - Batch")
print("2 - 2 per second")
print("3 - Real Time")
choice = raw_input("Enter feed speed choice (then press enter): ")
choice = int(choice)

if choice == 1:
print "running as batch"
delay == 0

elif choice == 2:
print "feeding 2 events per second"
delay == 0.5

elif choice == 3:
print "feeding real time"
delay = 'real time'

else:
print "choice not available"
os._exit(0)

print 'delay = ' + str(delay)


If I enter 1 or 2, I get delay = 7, if I enter 3, I get delay = real time.

HUH???

regards, Richard
--
All internal models of the world are approximate. ~ Sebastian Thrun
_______________________________________________
Tutor maillist - ***@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
richard kappler
2015-09-16 17:14:59 UTC
Permalink
Nevermind, figured it out. it needed to be delay = 0 and delay = 0.5, not ==

regards, Richard the virus ridden
Post by richard kappler
Missing something obvious here, but down with the flu so I'm foggy and
just can't see it. I need to set a variable 'delay' to be used in
time.sleep(delay) later on in a script, based on user input. Something odd
is going on in setting the variable though. Here's the snippet where I'm
#!/usr/bin/env python
delay = 7
print("1 - Batch")
print("2 - 2 per second")
print("3 - Real Time")
choice = raw_input("Enter feed speed choice (then press enter): ")
choice = int(choice)
print "running as batch"
delay == 0
print "feeding 2 events per second"
delay == 0.5
print "feeding real time"
delay = 'real time'
print "choice not available"
os._exit(0)
print 'delay = ' + str(delay)
If I enter 1 or 2, I get delay = 7, if I enter 3, I get delay = real time.
HUH???
regards, Richard
--
All internal models of the world are approximate. ~ Sebastian Thrun
--
All internal models of the world are approximate. ~ Sebastian Thrun
_______________________________________________
Tutor maillist - ***@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
Mark Lawrence
2015-09-16 20:43:29 UTC
Permalink
Post by richard kappler
Nevermind, figured it out. it needed to be delay = 0 and delay = 0.5, not ==
regards, Richard the virus ridden
Post by richard kappler
Missing something obvious here, but down with the flu so I'm foggy and
just can't see it. I need to set a variable 'delay' to be used in
time.sleep(delay) later on in a script, based on user input. Something odd
is going on in setting the variable though. Here's the snippet where I'm
#!/usr/bin/env python
delay = 7
print("1 - Batch")
print("2 - 2 per second")
print("3 - Real Time")
choice = raw_input("Enter feed speed choice (then press enter): ")
choice = int(choice)
print "running as batch"
delay == 0
print "feeding 2 events per second"
delay == 0.5
print "feeding real time"
delay = 'real time'
print "choice not available"
os._exit(0)
print 'delay = ' + str(delay)
If I enter 1 or 2, I get delay = 7, if I enter 3, I get delay = real time.
HUH???
regards, Richard
--
All internal models of the world are approximate. ~ Sebastian Thrun
I suggest that you learn a little about debugging problems like this,
such as putting print statements into your code or actually stepping
through your code in a debugger.

Would you also be kind enough not to top post here, it can make things
very difficult to read in long threads, thanks.
--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

_______________________________________________
Tutor maillist - ***@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
Continue reading on narkive:
Loading...