[Python-Dev] Re: Absolute/Relative import switcher for packages (PEP 328) (original) (raw)

Nicolas Fleury nidoizo at yahoo.com
Fri Jul 16 19:55:59 CEST 2004


Wiktor Sadowski wrote:

FWIW: Here is the solution for Absolute/Relative problem that we are using in our modified Python distribution...

We have added a few lines of code to to getparent in import.c. The code checks if there is "absimport=True" in parent dict and if so: absolute import is used in "child" module (getparent returns PyNone) Then putting "absimport=True" into an init.py is enough to force absolute import for the whole package. (The "absimport=True" switcher should be put into each subpackage init.py,if desired) Such addition is fully compatible with existing Python import syntax and easy to use. Also: absolute import could be default,and "relimport=True" would switch to relative import.

Personally, I would like very much to have a way to specify as default absolute imports in packages, instead of in modules. I would not mind if I have to specify it in all packages. The environment where I work uses a lot modules in few packages. A way to specify it in packages would ease our development until Python 2.6.

Regards, Nicolas



More information about the Python-Dev mailing list