Organizing Python

Martin Skott martin.skott at propylon.com
Mon Mar 19 16:56:09 EST 2001


whisper at oz.net (Dave LeBlanc) writes:

> What seems to be a reasonably trivial question to me, but i've not
> been able to find an answer in any of the Python doc i've looked at.
> 
> Is there a convention for installing 3rd party add-on modules into a
> Python installation so that:
> 	
> 	It's easy to update Python without reinstalling all the extras
> 
> 	One doesn't have to have a mile-long PYTHONPATH
> 
> I've seen some mention of packages and local/packages directories wrt
> to Linux installations, but I'm looking for a Windows solution.

This might have concerned overall package management eg. not only
Python, but the entire system. My preferred setup is to have a central
systemwide direectory with common modules and then a directory in my
homedirectory with my more personal modules, but then again that is on
Unix.
 
> I think part of why I have to ask this question is not quite
> understanding how PYTHONPATH and import works. When you say "import
> foo", then foo is taken to be a file and if you say "from foo import
> bar", then foo is taken to be a directory? Would this mean that one
> would have to have to have both foo and foo's parent directory in
> PYTHONPATH?

When you say import foo you add the namespace of the module foo to
your current namespace (all with the name foo.* ofcourse). When you
say from foo import bar then you import the name bar (eg. a class)
from the module foo. A module is usually represented by a file, but it
is also possible to have it be a directory which I once read something
about on python.org, but I can't find it now. What your PYTHONPATH
contains is a list of places to search for these modules. If your
PYTHONPATH names the directories /usr/lib/python and /home/me/modules
then these directories will always be searched when you in a script
use the import command.

-- 
Martin Skott
Software Developer
Propylon - Enabling Universal Mobility
http://www.propylon.com
Tel: +353 096 37245
Mobile: +353 087 9680370



More information about the Python-list mailing list