Edit:
I’m trying to check the user input against a array of allowed inputs to get a if statement to execute, a simple if you enter 'y' or 'yes' or 1 the code will run, i think i’m using the wrong constructs. 🙁
I have a really simple peiece of code that is meant to run user input against multiple possible conditions in a predefined array:
from spiders import test
run_test_spider = 0
condition = [1, 'yes', 'Yes', 'YES', 'y', 'Y']
x=-1
def spiders():
for run_test_spider in condition:
global x
x=x+1
if run_test_spider == condition[x]:
test.main()
print 'gotcha!'
print 'running.......'
print run_test_spider
print 'hello'
print 'hello would you like to run a test spider?'
print '1,yes,y = Yes I do!!!'
print '0,no,n = Nope!'
run_test_spider = raw_input(': ')
spiders()
I ran the debugger (pydev) in eclipse and once I input the string n to get a failed condition check, the debugger tells me the input automatically becomes 1, which causes the code to always execute the spider
does anyone know why my inputs are all becoming 1?
This 1 business is what eclipse is showing in its variables field, when I enter the input (once I step the debugger up to that point)
also the console spits out this: when I enter the input during debug:
Traceback (most recent call last):
File "C:\Program Files\eclipse\plugins\org.python.pydev.debug_2.5.0.2012040618\pysrc\pydevd_comm.py", line 755, in doIt
result = pydevd_vars.evaluateExpression(self.thread_id, self.frame_id, self.expression, self.doExec)
File "C:\Program Files\eclipse\plugins\org.python.pydev.debug_2.5.0.2012040618\pysrc\pydevd_vars.py", line 384, in evaluateExpression
result = eval(compiled, updated_globals, frame.f_locals)
File "<string>", line 1, in <module>
NameError: name 'n' is not defined
means that run_test_spider will be initialized with each element in condition.
So you actually check if each item of
conditionis in it…EDIT: So this is your check: