from __future__ import absolute_import issue

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Fri May 22 03:42:21 EDT 2009


En Wed, 20 May 2009 20:18:02 -0300, LittleGrasshopper  
<seattlehanks at yahoo.com> escribió:

> 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

absolute_import helps with imports inside a package (those are "relative"  
imports, relative to the package). If a module is located in a directory  
listed in sys.path, an absolute import will find it. I don't think there  
is a way to avoid shadowing a standard module (other than ensuring the  
standard directories come first in sys.path).

-- 
Gabriel Genellina




More information about the Python-list mailing list