from __future__ import absolute_import issue

LittleGrasshopper seattlehanks at yahoo.com
Wed May 20 19:30:18 EDT 2009


On May 20, 4:18 pm, LittleGrasshopper <seattleha... at yahoo.com> wrote:
> New to the group, this is my first post...
>
> It appears that either absolute imports (or my brain) aren't working.
> Given a module string.py which is in the same directory as a.py:
>
> #File a.py
> from __future__ import absolute_import
>
> import string
>
> print string # Module imported is string.py in current directory, not
> standard library module
>
> It imports the string module in the current directory, not the stirng
> module defined in the standard library.
>
> I've also noticed (by printing sys.path) that the current directory
> seems to always be included as the first element in sys.path, even
> when absolute_import is used.
>
> Any help appreciated.

I think I figured this out. Just because a module is in a directory
with an __init__.py module it doesn't put it inside the package. For a
module to be in a package, it must be imported through the package. If
it is just executed as a top-level script, or imported (but not
through the package) the module is for all effects not in a package.



More information about the Python-list mailing list