我有两个脚本sources.py
和nest.py
。他们是这样的
在来源.py在
import numpy as np
from nest import *
def make_source():
#rest of the code
def detect():
Nest = nest()
Nest.fit()
if __name__=='main':
detect()
在嵌套.py在
^{pr2}$当我像python sources.py
那样运行脚本时,它工作得很好。在
但是在Ipython笔记本环境中,如果我执行以下操作
In [1]: from sources import *
In [2]: detect()
我得到以下错误
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-5-e9c378341590> in <module>()
----> detect()
C:\sources.pyc in detect()
--> 7 Nest = nest()
C:\nest.pyc in _init_()
--> 7 self.source = make_source()
NameError: global name 'make_source' is not defined
我不明白为什么会这样。你能告诉我这两种情况有什么不同,以及如何解决这个问题吗?在
问题是
以及
^{pr2}$关于名称空间。在
如果有递归导入,最好不要执行“from something import*”或“import something as something”
这里有一个完整的解释:
Circular (or cyclic) imports in Python
相关问题 更多 >
编程相关推荐