PEP 328: Imports: Multi-Line and Absolute/Relative

Josiah Carlson jcarlson at nospam.uci.edu
Tue Mar 9 01:34:26 EST 2004


>   [-5.dirname.dirname.dirname]filename

The above is relatively clear, though the brackets kind of destroy the 
clarity.  For magical syntax, it isn't bad.  I prefer the standard 
semantics already offered:
from MODULE import NAMES as RENAME searching HOW
import NAMES as RENAME from MODULE searching HOW

Or for backwards compatibility:
from HOW.MODULE import NAMES as RENAME
import HOW.MODULE.NAMES as RENAME


Where HOW is of the form:
-<INTEGER>[.PACKAGE1[.PACKAGE2[...]]]
[PACKAGE1[.PACKAGE2[...]]]

With the search stepping up <integer> path levels, then traversing down 
through the listed packages, not stepping up any path levels when the 
-integer is not given, and raising a SyntaxError for -0 imports.  For 
example:

for HOW:
-1.sibling_package
maps to ../sibling_package/MODULE.(py|pyc|pyo|pyd|so|dll)

-2.uncle_package.cousin_package
maps to ../../uncle_package/cousin_package/MODULE.(ext)

-0.[other stuff]
should raise a SyntaxError

child_package.grandchild_package.great_grandchild_module
maps to ./child_package/grandchild_package/great_grandchild_module.(ext)


I think such behavior is clear enough magical syntax, what do others think?

  - Josiah



More information about the Python-list mailing list