[Python-Dev] import problems (original) (raw)

Steven D'Aprano steve at pearwood.info
Fri Nov 28 18:47:24 CET 2008


On Sat, 29 Nov 2008 03:30:49 am Christian Heimes wrote: ...

May I point you to the two leading underscores? The name 'import' clearly suggests that the function is part of Python's internals. By definition all attributes of the form * are not meant to be used directly.

What about doc, name and slots, to mention just a few?

I believe that import() is the recommended way to import a module known only at runtime. The docs also don't seem to agree with your assertion that import is not to be touched. On the contrary:

"The function is invoked by the import statement. It mainly exists so that you can replace it with another function that has a compatible interface..." http://docs.python.org/library/functions.html

Far from saying "Do Not Touch", the docs say "Please, go ahead and replace import if needed". If the OP wants "import x.y.z" to load module z instead of x, it seems to me that is exactly the problem import is designed to allow him to do.

Any suggestion to change the arguments of import() are futile. It's not going to happen unless the feature is required by Python's internal import system.

That may very well be true, but I don't know why you're dumping on me. It wasn't my suggestion to change import. I merely said I could see some advantages to it. I spent most of my post telling the OP why I thought his arguments were wrong!

-- Steven



More information about the Python-Dev mailing list