擅长:python、mysql、java
<p>增加了mhlester的答案。您需要删除<code>main</code>函数中的<code>print</code>语句。在</p>
<pre><code>import time
import thread
def input_thread(L):
derp = raw_input()
L.append(derp)
def show_thread(foo):
while 1:
print "Z is " + repr(Z) # Do not use backtick(`). Use `repr`
print "\n"
time.sleep(2)
def main():
global Z # declare `Z` as global
L = []
thread.start_new_thread(input_thread, (L,))
thread.start_new_thread(show_thread, (1,))
while 1:
if L:
Z = 2
# Remove following print statements,
# otherwise it will cover the terminal with empty lines.
#print L[0] < -
#print "\n" < -
Z = 1
main()
</code></pre>