It looks like you want to use a single instance of a World
class across several modules, which you can do easily by creating an instance of the World
class at the top level of your World
module, like this:
#module named World
class World():
def __init__(self):
self.world = Atlas()
world = World()
Now when you import World
in any of your other modules, you can use World.world
as the only instance of your World
class. This gets a little confusing, because World.world.world
is now the instance of Atlas
that the World
class creates, I would strongly suggest renaming something there.
Here is how your Greek_gods
module might look:
#module named Greek_gods
import World
class zeus():
world = World.world.world
Note that instead of putting world
into the initializer for the zeus
class, I made it a class attribute. This is because it looks like you want to share this Atlas
instance (which for some reason is called world
) among all zeus
instances. For an example of how this would look, check out the following code (which you could put into your Greek_gods
module to test):
z1 = zeus()
z2 = zeus()
assert World.world.world is z1.world is z2.world