Quick question…
I have a module enemies.py, containing classes like so:
class zombie(game_object):
"zombie"
pass
In my main python script, I first declare the game_object class, then import enemies
class game_object:
pass
import enemies
The enemies.py script complains that it can’t find game_object (to inherit from). How do I organize this?
Just a note, I want to be able to write a game.py, import game_mechanics which includes the class definition for a game_object, THEN import enemies which includes a bunch of subclass definitions of game_object.
Each file needs to import the modules it needs. There is no “super-global scope” in which you can import a module to automatically make it available to all other modules. Importing
game_mechanicswill not make it available in any module other than the one you import it in. Ifenemiesneeds access to things defined ingame_mechanics, then you have to doimport game_mechanics(or import the things you need fromgame_mechanics) from insideenemies. Example:Importing modules multiple times does not waste extra memory. The module is only loaded once, and when you import it multiple times, you just get multiple references to the same module.