好吧,我正在尝试设置 fileA
它的功能来自 fileB
.内部 file B
我使用了 file A
中的一些变量.是这样的:
fileA
import fileB
a = []
fileB.function1()
文件B是:
fileB
import fileA
def function1():
fileA.a.extend([2, 3])
但我收到此错误:
AttributeError: module 'fileB' has no attribute 'function1'
我知道有很多关于同一件事的问题,但我还没有看到任何人有这样的错误,直到现在我无法找到解决方案
最佳答案
在这种情况下,您可以使用本地导入而不是全局导入。我在 OpenStack 的源代码中看到了很多这样的内容。
f1.py
import f2
a = []
f2.function1()
f2.py
def function1():
import f1
f1.a.extend([2, 3])
关于python - Python 上的循环导入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59878923/