creating my own module search path

Bruce Sass bsass at
Mon Feb 26 03:17:46 EST 2001

On Sun, 25 Feb 2001, Sean 'Shaleh' Perry wrote:

> so, like a good little coder I use functions for code reusability and ease of
> maintenance.  I have a directory structure like:
> ./
>   frontend/
>   lib/
>   ...
> I would like to be able to load files in lib as python modules.  I know how
> to add the directory to sys.path.  The problem is I have a module named
> ''.  Sure, I could rename it.  But I can not possibly know the name of
> every module on a user's system.  What I was trying to do was add the path
> just before lib to the search path and load it as 'lib.util'.  But this does not
> work.  Suggestions anyone?

try this...

	cd .../site-packages
	mkdir sean
	cp ..././lib/ sean

restart the interpreter and (from an actual test)...

>>> from Bruce import util
imported from .../lib/python1.5/Bruce
>>> del util
>>> import Bruce.util
>>> Bruce.util.__doc__
'Bruce/ docstring.'

Bruce/ looks like this:

"""Bruce/ docstring."""

print "imported from .../lib/python1.5/Bruce"

I'm not sure how correct this is, but it should be on the right track.

Maybe also have a look at .../lib/pythonX.Y/

- Bruce

More information about the Python-list mailing list