[Python-Dev] Draft: PEP for imports (original) (raw)

Guido van Rossum guido at python.org
Fri Jan 30 10:29:19 EST 2004


Hello Guido,

Hello Armin,

> from /home/guido/lib/python import neatTricks

Keeping the amount of magic behind import as low as possible seems very important, because they are not a minor feature but something that every beginner must reasonably understand; I've already seen it as an obstacle. The above statement has the advantage of looking obvious; but in addition to the package name problem there is the fact that directory names are not always valid Python identifiers. A last try: import neatTricks in "/home/guido/lib/python" # no package import package.module in "/home/guido/lib/python" # package import foo in "." # relative import from neatTricks in "../cmds" import a, b, c s=os.path.join("some", "where"); import foo in s # expression path where the semantics would be to search sys.path if and only if no 'in' clause is specified. ('in' doesn't sound quite right...)

The 'from package at import module' syntax proposed later reads better, and the new keyword 'at' could be handled syntactically the same way as 'as'.

I'm still -0 on this feature. You say that every beginner must learn import. This is indeed true. But shouldn't they learn how to set the path right rather than learn how to import by filename? Setting the path is one of the things that everybody must learn about import anyway.

In any software endeavor, there comes a time when a piece of code is released with a reference to a file name that is only valid on the author's machine. I think we shouldn't encourage beginners to make such mistakes!

--Guido van Rossum (home page: http://www.python.org/~guido/)



More information about the Python-Dev mailing list