From: C A. R. <an...@ex...> - 2010-10-10 22:09:34
|
On Sun, Oct 10, 2010 at 3:01 PM, Bruce Sherwood <bas...@nc...> wrote: > Maybe I'm using the word "relative" incorrectly. I'll try to be more clear: > > Suppose in the site-packages/visual folder the file __init__.py has > "from visual.ui import display". That's clearly an absolute import; > the full path visual.ui is given. > > In the past, you could instead say "from ui import display", and this > was called a "relative" import. It had the problem of ambiguity with > some possible module named ui, outside the visual module, and so this > form was deprecated (and I think maybe it won't even work in Python > 3). > > Though I only became aware of this recently, since at least Python 2.6 > you can say "from .ui import display", where the dot makes this an > absolute import, with the dot standing for "visual.". In this > conversation I incorrectly called the dot form a "relative" import, > because it is relative to the current directory. But it is really an > absolute import, one that has the advantage that changing the name of > the surrounding directory doesn't require any changes to the files. No, you are using it correctly: http://www.python.org/dev/peps/pep-0328/#guido-s-decision The syntax was introduced to remove the ambiguity, because the old form was being removed at the same time. It's still a relative import, since the meaning of the import can change as folders are shuffled around. C Anthony |