Re: relative import broken?



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
.



Relevant Pages

  • RE: Duplicate name error after copying task/ VS_ISCORRUPT
    ... What you have to do is copy the assemblies that you want to reference ... Dim oApp As New Application, ... Dim oExec As Executable ... ' Get package path ...
    (microsoft.public.sqlserver.dts)
  • Error 713
    ... and include a reference to the Msdbrptr.dll ... This file is listed as Microsoft Data Report Designer v6.0 in the ... Manually include the Msdbrptr.dll file in the Package and ... <windows system>\MSDBRPTR.DLL ...
    (microsoft.public.vb.controls)
  • Re: How to make custom linked cross-references?
    ... If somebody wants the package on CTAN, ... a macro \p@which is intended for providing some ... A reference to section~of this book ... You might wish to take reference to yet another label within ...
    (comp.text.tex)
  • Re: How to make custom linked cross-references?
    ... If somebody wants the package on CTAN, ... a macro \p@which is intended for providing some ... A reference to section~of this book ... You might wish to take reference to yet another label within ...
    (comp.text.tex)
  • Re: Circular references ?
    ... > without causing the circular reference problem. ... > without a middleman package containing the object you want to pass between ... >> business types in it. ... >> to the common type (so in your case, put MyObject in the third project). ...
    (microsoft.public.dotnet.languages.vb)