[Python-Dev] Re: PEP 328 -- relative and multi-line import (original) (raw)

Aahz aahz at pythoncraft.com
Sat Apr 3 09:50:51 EST 2004


On Sat, Apr 03, 2004, David Goodger wrote:

I have Aahz's revision ready to check in, but I'm unclear on one point. Is the accepted/pronounced relative import syntax dots only, or can there be a branch too? In other words, is the "Y" here acceptable (where Y is a sibling to the current module's package)? from ..Y import X I think the PEP needs a clear statement (and examples) of which syntax and semantics have been chosen.

Good point. Here's what I think the semantics are; as soon as I get agreement, I'll update the PEP. Given a package layout::

package
    subpackage1
        moduleX
        moduleY
    subpackage2
        moduleZ
    moduleA

Each leading "." refers to one level of parent. Assuming that the current file is moduleX.py, following are correct usages of the new syntax::

from .moduleY import spam
from ..subpackage1 import moduleY
from ..subpackage2.moduleZ import eggs
from ..moduleA import foo
from ...package import bar

Actually, I believe that this is the only possible useful semantic; I would welcome clear reasoning for another semantic.

Here's a question. Should the following be legal? ::

from ...sys import path

If not, do we test for it? What kind of error do we raise?

Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/

"usenet imitates usenet" --Darkhawk



More information about the Python-Dev mailing list