怎么if __name__ == "__main__":办?
# Threading example
import time, thread
def myfunction(string, sleeptime, lock, *args):
while True:
lock.acquire()
time.sleep(sleeptime)
lock.release()
time.sleep(sleeptime)
if __name__ == "__main__":
lock = thread.allocate_lock()
thread.start_new_thread(myfunction, ("Thread #: 1", 2, lock))
thread.start_new_thread(myfunction, ("Thread #: 2", 2, lock))
Run Code Online (Sandbox Code Playgroud) while True:
reply = input('Enter text')
if reply == 'stop': break
print(reply.upper())
Run Code Online (Sandbox Code Playgroud)
结果是:
Run Code Online (Sandbox Code Playgroud)Enter text:Traceback (most recent call last): File "C:\PythonProjects\5.py", line 2, in <module> reply = input('Enter text:') EOFError: EOF when reading a line [Finished in 0.2s with exit code 1]
它只在Sublime Text 2.我试过IDLE,试过命令行,一切都很完美.为什么Subleme会对我大喊大叫?
顺便说一句,也许你也可以解释我在这种情况下可能意味着什么.当然,我在文档中已经读过,如果从输入中读取EOF,则会引发相应的错误.我想模仿这种情况.仅输入键盘?如果是,我应该输入什么组合键才能获得EOF?
先感谢您.