I’m working on a text adventure that stores the levels as a massive dictionary called ‘places’. Instead of having it in the main file, I thought that I would make a separate file called ‘levels.py’ that would contain it, making my code cleaner and eliminating the need to go through 450+ lines of other code to add to it.
So, the main game file:
from levels import places
class Thing:
#Some stuff
levels.py:
from game import *
places = {
"bleh" : Thing("bleh"),
}
It seems like ‘places’ isn’t defined in the game, however.
I think that what’s happening is that there’s an import ‘loop’. However, if levels.py needs to import classes from game.py, how could I prevent something like that?
It’s always possible to refactor to eliminate circular dependencies. Move
Thingtothing.py, then ingame.pyand inlevels.pyusefrom thing import Thing. Rinse and repeat.