編集:許可された入力の配列に対してユーザー入力をチェックして、実行するifステートメントを取得しようとしています'y' or 'yes' or 1
。コードを入力すると単純に実行されます。間違った構造を使用していると思います。:(
事前定義された配列内の複数の可能な条件に対してユーザー入力を実行することを目的とした、非常に単純なコードがあります。
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()
私はEclipseでデバッガー(pydev)を実行し、文字列を入力しn
て失敗した条件チェックを取得すると、デバッガーは入力が自動的に になることを通知します1
。これにより、コードは常にスパイダーを実行します
私の入力がすべてになっている理由を誰かが知ってい1
ますか?
この1
ビジネスは、入力を入力したときにEclipseが変数フィールドに表示しているものです(デバッガーをその時点までステップアップすると)
また、コンソールはこれを吐き出します:デバッグ中に入力を入力すると:
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