[Python-Dev] Re: PEP 328 -- relative and multi-line import
Neil Schemenauer
nas-python at python.ca
Mon Apr 5 13:51:17 EDT 2004
On Mon, Apr 05, 2004 at 01:36:24PM -0400, Aahz wrote:
> Your intuition is wrong. From package's __init__.py, ``from .`` refers
> to package's parent; to get back into the package, you need to use
> ``from .package``.
That's confusing. I expected '.' to refer to the current package,
just as '.' refers to the current directory in most file systems. I
think that meaning would be more useful in practice as well.
Imagine a package where '.' means the current package:
# __init__.py ###################################
from .a import A
from .b import B
#################################################
# a.py ##########################################
from .utils import x, y
class A:
...
#################################################
# b.py ##########################################
from .utils import x, z
class B:
...
#################################################
# utils.py ######################################
def x():
...
def y():
...
def z():
...
#################################################
Notice that the modules that make up the package do not need to know
what the package is called. That was one of the major benefits of
relative imports that I was looking forward to.
Perhaps I misunderstand the PEP.
Neil
More information about the Python-Dev
mailing list