[Python-Dev] status of absolute_import w/ python 2.7

Sylvain Thénault sylvain.thenault at logilab.fr
Fri Jul 8 15:51:19 CEST 2011


Hi there,

the documentation state that absolute_import feature is the default
behaviour with python 2.7, though it seems that it behave differently
with the __future__ import :

$ cat package/__init__.py

import subpackage

$ python2.7
Python 2.7.1+ (default, Apr 20 2011, 22:33:39) 
[GCC 4.5.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import package
>>> 

$ cat package/__init__.py

from __future__ import absolute_import
import subpackage

$ python2.7
Python 2.7.1+ (default, Apr 20 2011, 22:33:39) 
[GCC 4.5.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import package
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "package/__init__.py", line 23, in <module>
    import subpackage
ImportError: No module named subpackage


Maybe the doc should be fixed ?
-- 
Sylvain Thénault                               LOGILAB, Paris (France)
Formations Python, Debian, Méth. Agiles: http://www.logilab.fr/formations
Développement logiciel sur mesure:       http://www.logilab.fr/services
CubicWeb, the semantic web framework:    http://www.cubicweb.org



More information about the Python-Dev mailing list