请大哥们帮忙找错 。。。
import threading, time, sys
def sleepandprint():
time.sleep(1)
print "Hello from both of us. "
def threadcode():
stdout.write( "Hello from the new thread. My name is %s\n " %
threading.currentThread().getName())
sleepandprint()
print "Before starting a new thread, my name is ", \
threading.currentThread().getName()
t = threading.Thread(target = threadcode, name = "ChildThread ")
t.setDaemon(1)
t.start()
sys.stdout.write( "Hello from the main thread. My name is %s\n " %
threading.currentThread().getName())
sleepandprint()
t.join()
不知道为什么 我去掉 IMPORT SYS 或者加上 都会出现
NameError: global name 'stdout ' is not defined
[解决办法]
import sys
...
sys.stdout. ...
或者
from sys import stdout
...
stdout...