从不同的模块导入函数 - python

时间:2015-02-04 08:02:10

标签: python import

我正在使用

从模块 - mod导入函数 - func
from mod import func

并将其用作

X=func(x,y)

但在执行该函数之前,我的程序正在执行整个模块。 如何让它只执行函数?

1 个答案:

答案 0 :(得分:1)

如果您想避免模块执行,请将代码放在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?

相关问题