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 and root/module2 be in sys.path which can be done like this in somescript :

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.

Edited 6 Years Ago by griswolf: n/a

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."

This question has already been answered. Start a new discussion instead.