importing a sibling module
Clark C . Evans
cce at clarkevans.com
Fri Jan 4 11:23:52 EST 2002
On Fri, Jan 04, 2002 at 11:14:58AM +0100, Alex Martelli wrote:
| > folder files
| > /zz/V13/lib tool.py
| > /zz/V13/app prog.py
| > /zz/V14/lib tool.py
| > /zz/V14/app prog.py
| ...
| > What I'd like to do, within prog.py is "import ../lib/tool.py"
...
| import os, sys, imp
| app_dir, appfilename = os.path.split(sys.argv[0])
| lib_dir = os.path.join(app_dir,'../lib')
| imp.load_module('tool', *imp.find_module('tool',[libdir]))
Thank you Alex; unfortunately, this returns an app_dir of ''
Is there any way to ask a module for it's pathname? Say
__mypath__ returns this. Then I could pop "app" from the
path, push "lib" on the path and then import tool.py using
the technique you described.
Best,
Clark
More information about the Python-list
mailing list