[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] Directories



Kris Schnee schrieb:
I'm trying to organize my code better. I've got modules and data files organized into directories like so:

Main Game Directory
  -Music, sound, etc.
  -Conch (sound code)
  -Aquablue (worldsim)
  -Driftwood (UI)
  -Pearl (Isometric display)

And here I've encountered a problem. I've been able to test each module on its own, and even have them automatically go up one directory to access the right data files when run alone by saying:

if __name__ != "__main__": ## Run when included in something else
    print "Loaded module "+MODULE_NAME+"."
else: ## Run when this program is run by itself
    print "Running module "+MODULE_NAME+", v"+VERSION
    if MODULE_NOTES:
        print MODULE_NOTES

    ## Switch to the next directory up to find data directories.
    os.chdir(os.path.split(os.getcwd())[0])

But the part I'm working on right now, the "Pearl" display, needs to access the Aquablue worldsim code just to be properly tested. If I put "import Aquablue" below the code I just gave, it can't find the module even though it can access the data-file directories. Will I have to either put Pearl in the main game directory so it can find Aquablue, or test it without that?

Kris


Hi

http://www.python.org/doc/essays/packages.html (got it from python 2.4 documentation)

You need to make packages and you have to create the __init__.py files for each packages (details see link). And if I remember right, you have to acces a subpackage with the full identifier. Example:
import Game.Aquablue.worldsim # you have to do that even if you want to import the worldsim in Game.Pearl.isoview


~DR0ID