Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个 python 脚本,其中有一行:
if __name__ == "__main__": ...
那么如何在导入上面的脚本后在另一个脚本中运行这部分代码呢?
谢谢。
使其成为一个独立的功能。
def run_main(): .... if __name__ == "__main__": run_main()
你可以run_main()从另一个文件调用。
run_main()