
On Mon, Apr 05, 2004, Neil Schemenauer wrote:
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.
Not sure. The only difference between your semantics and mine lies in __init__.py; there -- and only there -- is where the need exists to know the package name. You're making the mistake of thinking that __init__.py exists in the same namespace as a.py, b.py, and utils.py -- it doesn't. Now, we could in theory use your semantics due to "practicality beats purity", but it seems to me that it would lead to more mistakes in understanding how packages work. -- Aahz (aahz@pythoncraft.com) <*> http://www.pythoncraft.com/ Why is this newsgroup different from all other newsgroups?