Script for a project inside own directory
Maxim Khitrov
mkhitrov at gmail.com
Sun Mar 22 11:41:37 EDT 2009
2009/3/22 Filip Gruszczyński <gruszczy at gmail.com>:
> 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.
import sys
sys.path.append('<path to project>')
If project directory is one level up, you can do something like this:
import os
import sys
sys.path.append(os.path.realpath('..'))
- Max
More information about the Python-list
mailing list