Relative Imports, why the hell is it so hard?
gagsl-py2 at yahoo.com.ar
Tue Mar 31 04:55:37 CEST 2009
En Mon, 30 Mar 2009 21:15:59 -0300, Aahz <aahz at pythoncraft.com> escribió:
> In article <mailman.2591.1237922208.11746.python-list at python.org>,
> Gabriel Genellina <gagsl-py2 at yahoo.com.ar> wrote:
>> I'd recommend the oposite - use relative (intra-package) imports when
>> possible. Explicit is better than implicit - and starting with 2.7 -when
>> "absolute" import semantics will be enabled by default- you'll *have* to
>> use relative imports inside a package, or fail.
> Really? I thought you would still be able to use absolute imports; you
> just won't be able to use implied relative imports instead of explicit
> relative imports.
You're right, I put it wrongly. To make things clear, inside a package
"foo" accessible thru sys.path, containing a.py and b.py:
Currently, the "a" module can import "b" this way:
from foo import b
from . import b
When implicit relative imports are disabled ("from __future__ import
absolute_import", or after 2.7 supposedly) the last one won't find b.py
(I hope I put it right this time).
More information about the Python-list