importing a sibling module
Chris Liechti
cliechti at gmx.net
Fri Jan 4 17:14:48 EST 2002
"Clark C . Evans" <cce at clarkevans.com> wrote in
news:mailman.1010160546.8297.python-list at python.org:
> 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 ''
try os.path.abspath() to get a canonical path...
> 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
--
Chris <cliechti at gmx.net>
More information about the Python-list
mailing list