相关疑难解决方法(0)

如果__name__ =="__ main__":怎么办?

怎么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)

python program-entry-point idioms namespaces python-module

5545
推荐指数
36
解决办法
261万
查看次数

Python 3:读取一行时的EOF(Sublime Text 2很生气)

while True:
    reply = input('Enter text')
    if reply == 'stop': break
    print(reply.upper())
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]
Run Code Online (Sandbox Code Playgroud)

它只在Sublime Text 2.我试过IDLE,试过命令行,一切都很完美.为什么Subleme会对我大喊大叫?

顺便说一句,也许你也可以解释我在这种情况下可能意味着什么.当然,我在文档中已经读过,如果从输入中读取EOF,则会引发相应的错误.我想模仿这种情况.仅输入键盘?如果是,我应该输入什么组合键才能获得EOF?

先感谢您.

python eof python-3.x sublimetext2

34
推荐指数
4
解决办法
11万
查看次数