creating my own module search path
bsass at freenet.edmonton.ab.ca
Mon Feb 26 09:17:46 CET 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:
> 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
> 'util.py'. 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?
cp ..././lib/util.py sean
restart the interpreter and (from an actual test)...
>>> from Bruce import util
imported util.py from .../lib/python1.5/Bruce
>>> del util
>>> import Bruce.util
Bruce/util.py looks like this:
print "imported util.py 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/site.py.
More information about the Python-list