relative import broken?
Peter Otten
__peter__ at web.de
Wed Apr 30 10:12:17 EDT 2008
test wrote:
> basic noob question here.
>
> i am trying to reference a package, i have the structure:
>
> mypack/
> __init__.py
> test.py
> subdir1/
> __init__.py
> mod1.py
> subdir2/
> __init__.py
> mod2.py
>
> can someone please tell me why the statement:
>
> from mypack.subdir1.mod1 import *
>
> does NOT work from mod2.py nor from test.py?
>
> instead, if i use:
>
> from subdir1.mod1 import *
>
> it works perfectly from test.py.
>
> ....?
The parent directory of mypack must be in the module search path, see
http://docs.python.org/tut/node8.html#l2h-19
The least intrusive way to achieve this is to move test.py one level up in
the directory hierarchy.
Peter
More information about the Python-list
mailing list