怎么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) 所以我启动了pyscripter,我得到了一个文件:
def main():
pass
if __name__ == '__main__':
main()
Run Code Online (Sandbox Code Playgroud)
那是什么?为什么我的程序在没有它的情况下工作?无论如何,这是什么目的?我的代码会在哪里?让我们说一个打印你好世界的功能.那会怎么样?我在哪里打电话给它?