[Tutor] Module Packages

Zak Arntson zak at harlekin-maus.com
Wed Oct 29 18:12:46 EST 2003


I'm writing a Python roguelike (in Pygame, whee!), and have started
splitting my initial file up into multiple files. So I figured this would
be a good time to learn about packages.

In the one-file format, I have the following classes (well, I have more,
but these are the relevant ones):

class Entity
class Player(Entity)
class Zombie(Entity)
class Game

Now, game makes use of both the Player and the Zombie classes, by creating
instances of both. Ideally, I'd like to separate things into subitems:

/Pyrl
    /Entity
        Entity.py
        Player.py
        /Monster
            Zombie.py
    Game.py

First question, then, is this a properly done package structure? I'd like
to be able to do the following:
    plr = Entity.Player()
    zom1 = Entity.Monster.Zombie()
    zom2 = Entity.Monster.Zombie()

But it looks like I'll have to:
    plr = Entity.Player.Player()
    zom1 = Entity.Monster.Zombie.Zombie()
    zom2 = Entity.Monster.Zombie.Zombie()

Is there anyway to avoid the "double-referencing"? Or am I going about my
package organization all wrong?

---
Zak Arntson
www.harlekin-maus.com - Games - Lots of 'em



More information about the Tutor mailing list