【发布时间】:2016-10-12 17:24:09
【问题描述】:
我有这个模块调用 main() 函数:
## This is mymodules ##
def restart():
r = input('Do you want to build another configuration file?\n1. Yes\n2. No\n')
if r == '1':
main()
elif r == '2':
os.system('pause')
main() 位于加载此模块的另一个脚本中。但是,当它调用时,它说 main() 未定义。基本上这就是我在测试中所拥有的:
import mymodules as my
def main():
print('good')
my.restart()
当它运行时,我希望 my.restart() 能够调用定义的 main()。
【问题讨论】:
-
main()不在您的第一个模块的名称空间中。你可以导入它,但一般you should avoid circular imports unless you are careful.
标签: python function import module