<font size="4">I'm stil totally stuck with relative imports, i' ve tried the example tree from PEP 328 without any result:<br></font><font size="2"><br></font><pre class="literal-block"><font size="4">package/<br>    __init__.py<br>
    subpackage1/<br>        __init__.py<br>        moduleX.py<br>        moduleY.py<br>    subpackage2/<br>        __init__.py<br>        moduleZ.py<br>    moduleA.py<br><br>Assuming that the current file is either <tt class="docutils literal"><span class="pre">moduleX.py</span></tt> or<tt class="docutils literal"><span class="pre"> subpackage1/__init__.py</span></tt>, following are correct usages of the new syntax:</font><br>
</pre>

<pre class="literal-block"><font size="2"><font size="4">from .moduleY import spam<br>from .moduleY import spam as ham<br>from . import moduleY<br>from ..subpackage1 import moduleY<br>from ..subpackage2.moduleZ import eggs<br>
from ..moduleA import foo<br>from ...package import bar<br>from ...sys import path</font><br></font></pre>I always get:<br><br>Traceback (most recent call last):<br>  File "moduleY.py", line 1, in <module><br>
    from ..moduleA import a<br>ValueError: Attempted relative import in non-package<br><br><br><div class="gmail_quote">2011/2/27 Frank Millman <span dir="ltr"><<a href="mailto:frank@chagford.com">frank@chagford.com</a>></span><br>
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;"><br>
"Steven D'Aprano" <<a href="mailto:steve%2Bcomp.lang.python@pearwood.info" target="_blank">steve+comp.lang.python@pearwood.info</a>> wrote in message news:4d6a56aa$0$29972$c3e8da3$5496439d@news.astraweb.com...<div class="im">
<br>
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
On Sun, 27 Feb 2011 12:08:12 +0200, Frank Millman wrote:<br>
<br>
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
Assume the following structure -<br>
<br>
main.py<br>
/pkg<br>
    __init__.py<br>
    mod1.py<br>
    mod2.py<br>
<br>
main.py<br>
    from pkg import mod1<br>
<br>
mod1.py<br>
    import mod2<br>
<br>
mod2.py<br>
  import mod1<br>
</blockquote>
<br>
<br>
If you change the "import mod*" lines to "import pkg.mod*" it works for<br>
me in Python 3.1 and 3.2.<br>
<br>
According to my understand of PEP 328, "from . import mod*" should work,<br>
but I agree with you that it doesn't.<br>
<br>
If you get rid of the circular import, it does work. So I suspect a bug.<br>
<br>
<br>
</blockquote>
<br></div>
Thanks, Steven.<br>
<br>
I confirm that 'import pkg.mod* works. Unfortunately I am using sub-packages as well, which means that to refer to an object in the sub-package I need to use w.x.y.z every time, which gets to be a lot of typing! I will stick to my hack of putting the package name in sys.path for now, unless someone comes up with a better idea.<br>
<font color="#888888">
<br>
Frank</font><div><div></div><div class="h5"><br>
<br>
<br>
-- <br>
<a href="http://mail.python.org/mailman/listinfo/python-list" target="_blank">http://mail.python.org/mailman/listinfo/python-list</a><br>
</div></div></blockquote></div><br>