2024-04-26 10:27:21 发布
网友
我正在从module-mod导入一个function-func,使用
from mod import func
把它当作
X=func(x,y)
但是在执行函数之前,我的程序正在执行整个模块。 如何使其仅执行函数?你知道吗
如果要避免模块执行,请将模块中的代码放在main下
main
# stuff to run always here such as class/def def main(): pass if __name__ == "__main__": # stuff only to run when not called via 'import' here main()
更完整的答案: Why is Python running my module when I import it, and how do I stop it?
如果要避免模块执行,请将模块中的代码放在
main
下更完整的答案: Why is Python running my module when I import it, and how do I stop it?
相关问题 更多 >
编程相关推荐