packages
Jaime Wyant
programmer.py at gmail.com
Mon Apr 18 14:45:14 EDT 2005
A package is a collection of related modules. The modules are
'collected' in a directory that contains a special __init__.py script.
Put this directory some where in your PYTHONPATH and you can do stuff like ->
from mypackage.mymodule import MyObject
The tutorial uses a sound package as its example. The idea being that
the Sound package contains sub packages. For instance the
sound.effects package represents some specific sound effect such as:
`echo', 'surround', 'reverse'.
This means that you have a directory structure like (stripped from the
tutorial) ->
Sound/ Top-level package
__init__.py Initialize the sound package
Effects/ Subpackage for sound effects
__init__.py
echo.py
surround.py
reverse.py
What I *dont* like about the example is the PascalStyleCasing used for
the package names. Is their not some *suggested* standard on naming
conventions? This is one of my few gripes about python! The
libraries seem to be written without regards to a consistent naming
standard. Some modules, such as the logging module use camelCasing
while others such as the string module use lowercaseruntogether
methods.
I hope that python 3000 addresses this! Me, I've just gotten used to
RTFM'n. Doh! Tangent! Anyway...
Another example of packages that I use is for building my GUI.
Because I don't have many `screens', I break things up into packages
like this:
myapp.panels (contains all of the `panels' i use)
myapp.dialogs (contains all of the dialogs i use)
myapp.database (contains database related modules)
Which allows me to do something like this in my app ->
from myapp.panels.firsttimepanel import FirstTimePanel
Get it?
jw
On 4/18/05, Mage <mage at mage.hu> wrote:
> Hello,
>
> I read about modules and packages in the tutorial. I think I understand
> how to use packages and modules, even I know how to create a module (as
> far I understand it's a simple .py) file , but I don't know how can I
> create a package and when should I do it.
>
> Where should I look for more information?
>
> Mage
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
More information about the Python-list
mailing list