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

Armin Rigo arigo at tunes.org
Fri Jan 30 18:40:33 EST 2004


Hello,

On Fri, Jan 30, 2004 at 09:26:13AM -0500, Jp Calderone wrote:

> 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

An experienced Python programmer could probably use this to some advantage, but I think many beginners would use it without realizing it will very easily result in a piece of software which is completely undistributable.

Point taken. As far as I can see I believe that the whole module system problably needs some more in-depth rethinking at some point. For the beginner the package system is baffling, and for the advanced user it lacks precise control over what is imported from where, for the cases where it is really needed.

[tentative development]

In the multi-directory projects I am familiar with, I've seen two cases:

I never find myself using "import package.module" but always "from package import module". Actually I still have to be convinced that packages are a Good Thing. As far as I am concerned, sys.path hacks are the only case in which I miss a Python feature sufficiently to have to copy similar custom code all around my projects.

A more radical point of view is that these sys.path hacks are here not because of a missing feature, but on the contrary to work around the way Python tries to isolate me from the "messiness out there" (the file system) by mapping it into a neat language construct (packages). Trying to map a user-controlled structure over another, different one is a receipt for eventual confusion, however good the design is.

I think I'd prefer to have just a reasonably natural way to talk about modules -- and files in general -- relative to the current module or the standard library. This is only a vague idea, but I believe it would fit better into (at least my view of) Python's philosophy: keep the language simple by avoiding abstraction layers that are not "natural", i.e. that do some kind of remapping of concepts, as opposed to just expose a higher-level view of the same concepts.

A bientot,

Armin.



More information about the Python-Dev mailing list