这个问题可能在此论坛上得到了回答,但我没有找到它。
所以我的问题如下: 假设我正在使用两个脚本:
#script 1
import script2
reload (script2)
from script2 import *
def thisisatest():
print "test successfull"
return ()
def main():
realtest()
return ()
main()
和
#script 2
def realtest():
thisisatest()
return()
现在,如果我运行script1,我会收到一条错误消息,指出未定义全局名称“thisisatest”。然而这是最好的()?调用python为我提供了函数帮助。
编辑:
我的问题是:在一个脚本中执行导入部分(对于所有脚本)是否有办法继续处理许多脚本,或者这是不可能的?
提前致谢,
Enzoupi
答案 0 :(得分:0)
最好完全避免循环依赖。如果module1从module2导入,则module2不应从module1导入。如果module2中定义的函数需要使用module1中的函数,则可以将该函数作为参数传递。
模块1:
from module2 import otherfunc
def myfunc()
print "myfunc"
def main()
otherfunc(myfunc)
main()
模块2:
def otherfunc(thefunc):
print "otherfunc"
thefunc()