Python 3 中的导入顺序

Import order in Python 3

我的程序中有一些导入问题,

在main.py中:

from world import *
from dialogue import *
from event import *

在dialogue.py中:

from world import *
from event import *

class 区域在 world.py 中定义,但是当我尝试使用 dialogue.py 中的区域 class 时,它 returns

builtins.NameError: name 'Area' is not defined

如果我将 main.py 中的导入顺序更改为

from dialogue import *
from world import *
from event import *

当我尝试从 world.py 访问对话 class 时,我得到了这个

builtins.NameError: name 'Dialogue' is not defined

我认为导入的顺序应该没有什么不同?如何从我的所有文件访问我的所有 classes?

The class Area is defined in world.py, yet when I try to use the Area class from dialogue.py it returns

您导入代码的方式有误。从两个模块中导入 *;这混淆了 Python,因为两个模块都有一个名为 Area.

的 class

而不是使用 *(野生导入)将它们导入为模块

import dialogue
import world
import event

d1 = world.Dialogue()
d2 = dialogue.Dialogue()