I think it would be
import os os.path.join('root/module1') os.path.join('root/module2') import somescript import someotherscript
You need that
root/module2 be in
sys.path which can be done like this in
import os import sys rootpath = os.path.dirname(os.path.abspath(os.curdir)) sys.path.append(rootpath) mod2path = os.path.join(rootpath,'module2') sys.path.append(mod2path) import common import someotherscript
Of course you also need to be sure that all these things exist; it would be nice not to double add them (doesn't actually hurt) to sys.path; and other niceties. You may want to create an empty file named
__init__.py in the various directories. See http://effbot.org/pyfaq/what-is-init-py-used-for.htm.
Try relative imports.
Seem like just the thing. I've used them. They permit you to import modules from a relative parent package.
They're hard to figure out though. The documentation is somewhat lacking so you might have to tinker until you get it right.
I'm not a fan of, for example
from canvas import point because I've spent far too much of my time dealing with subtle bugs introduced by, for example,
from coastline import point in the same chunk of code. (Mostly, I admit, not in Python). I just like the self documentation and safety of seeing for example
import canvas import coastline myCorner = canvas.point(200,400) myPromontory = coastline.point(43.32576, -124.38773)
Thus, I'm also not very fond of relative imports. Not saying "bad", but just "I dunno, maybe not usually for me."
I'm talking about dotted relative imports.