Script for a project inside own directory

R. David Murray rdmurray at bitdance.com
Sun Mar 22 17:22:37 CET 2009


=?UTF-8?Q?Filip_Gruszczy=C5=84ski?= <gruszczy at gmail.com> wrote:
> I am having a project built like this:
> 
> project
>    module1.py
>    module2.py
>    packages1/
>      module3.py
> 
> etc.
> 
> I have script that uses objects from those modules/packages. If I keep
> this script inside project directory it's ok and it works. But I would
> like to move it to own scripts directory and from there it doesn't
> work. I think I understand why it doesn't work (the root of local
> packages and modules is there and it can't see what it above it), but
> I would like to ask if there is any workaround? I would like to keep
> all my scripts in separate dir instead of main dir. I like to keep it
> clean.

You need to put your project directory on the PYTHONPATH one way
or another.  I would suggest reading up on how the module search
path works in python (PYTHONPATH, sys.path) so that you can decide
which of the many possible ways to make this work will serve you
best.

--
R. David Murray           http://www.bitdance.com




More information about the Python-list mailing list