import from environment path

Guillaume Martel-Genest guillaumemg at gmail.com
Fri Jun 17 13:43:36 EDT 2011


Hi,

Here's my situation : I got a script a.py that need to call b.py. The
2 scripts can't be in a same package. Script a.py knows the path of
b.py relative to an environment variable B_PATH, let's say B_PATH/foo/
b.py. The solution I found is to do the flowwing :

b_dir = os.path.join(os.environ['B_PATH'], 'foo')
sys.path.append(b_dir)
import b
b.main()

Is it the right way to do it, should I use subprocess.call instead?



More information about the Python-list mailing list