我不明白为什么第一次“def run”时会出现缩进错误import threading, time, sys
class Listen:
def __init__(self):
print "Choose a direction. Forwards (1) or Backwards (2) or to quit type 'quit'"
direction = 0
def run (threadName):
while 1==1 :
print "%s Listening for direction: " %(threadName)
direction = input
time.sleep(1)
if (direction != 1 or 2):
print "You entered a incorrect value"
elif (direction=='quit'):
break
thread.exit()
else:
return direction
class Store:
def run (threadName, direction):
print "%s %s" %(threadName, direction)
if __name__ == '__main__':
l = Listen()
s = Store()
listeningThread = threading.Thread(target=l.run, args=())
storingThread = threading.Thread(target=s.run, args=())
listeningThread.start()
storingThread.start()
我要做的是在listengthread中存储一个值,同时listengthread会不断地监听新的输入来替换当前存储的值。在
但由于我是Python新手,我已经与这个错误纠结了很长一段时间了,尽管我还是可以问一下有帮助的人:)