Package organization
Steve Holden
steve at holdenweb.com
Mon Jul 17 07:44:38 EDT 2006
Mike Wyatt wrote:
> I've been playing around with Python for a few months now, and I just
> recently started looking at packages to organize my growing project. So
> far, I've been organizing my application into one class per module.
> This has been working pretty well. For example, I simply "import
> timer", then use "t = timer.Timer()" to allocate a new Timer object, .
> Unfortunately, this is yielding some pretty odd syntax when I use
> packages. Here is a sample of my package structure:
>
> /engine
> /graphics
> /input
> /world
> /timer
> timer.py # contains Timer class
> main.py
>
> Let's say I want to create a Timer object in main.py. I would need to
> do something like this:
>
> import engine.timer.timer.Timer
> t = engine.timer.timer.Timer()
>
> Maybe I shouldn't have a module and package with the same name, but it
> seems the most logical design. Unfortunately, the code is a bit ugly
> with "timer" included in the import three times.
>
> Is there a better way to do this? How do you guys organize your
> packages and modules?
Basically you are over-organizing for your needs here. Is there any
reason why the timer.py file defininf the Timer function needs to be in
its own sub-package?
It's bad enough having to write timer.Timer(), don't compound that folly
unnecessarily!
regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden
More information about the Python-list
mailing list