[Python-ideas] import imports
denis.spir at free.fr
Tue Jan 27 10:39:05 CET 2009
[Sorry, forgot to answer one of the questions in my previous reply.]
Le Mon, 26 Jan 2009 22:38:24 -0000,
"Alan Gauld" <alan.gauld at btinternet.com> a écrit :
> "spir" <denis.spir at free.fr> wrote
> > === package module lookup ===
> > This would also encourage the good practice of never
> > writing absolute imports -- which is a plague.
> I'm not sure what you mean by absolute imports. If you mean
> giving the physical path to the file then You cannot really do
> that in Python. I don't understand the comment?
What I call "absolute import" happens when you give python an absolute path to look for a module (even if its your own). For sure python does not let you write an absolute path in the import instruction itself, but people do that by appending to PYTHONPATH, using 'sys.path'. Some installation instructions even explicitely tell the users to do that.
More commonly, application/package authors often rely on absolute pathes for internal imports (meaning that you cannot even chose the dir's name! not to talk about the actual location...) or external ones.
Actually, for external imports, the only solutions I know are either to use environment variables, or to rely on python standard locations for packages (which are relative to python's root path, itself defined as an environment variable).
For intra-package imports, there are now facilities to write relative imports directly:
la vida e estranya
More information about the Python-ideas