I'm having a few issues with a number of imports in my program,
In main.py:
from world import *
from dialogue import *
from event import *
In dialogue.py:
from world import *
from event import *
The class Area is defined in world.py, yet when I try to use the Area class from dialogue.py it returns
builtins.NameError: name 'Area' is not defined
If I change the order of the imports in main.py to
from dialogue import *
from world import *
from event import *
When I try to access the dialogue class from world.py, I get this
builtins.NameError: name 'Dialogue' is not defined
I thought the order of imports shouldn't have made a difference? How can I access all of my classes from all of my files?
The class Area is defined in world.py, yet when I try to use the Area class from dialogue.py it returns
The way you are importing your code is wrong. From both modules you are importing with *
; this confuses the Python, because both modules have a class called Area
.
Instead of using *
(wild import) import them as modules
import dialogue
import world
import event
d1 = world.Dialogue()
d2 = dialogue.Dialogue()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.