from __future__ import absolute_import ?
Peter Otten
__peter__ at web.de
Fri Feb 2 12:22:44 EST 2007
Ron Adam wrote:
>
> from __future__ import absolute_import
>
> Is there a way to check if this is working? I get the same results with
> or without it.
>
> Python 2.5 (r25:51908, Sep 19 2006, 09:52:17)
> [MSC v.1310 32 bit (Intel)] on win 32
If there are two modules 'foo', one at the toplevel and the other inside a
package 'bar',
from __future__ import absolute_import
import foo
will import the toplevel module whereas
import foo
will import bar.foo. A messy demonstration:
$ ls bar
absolute.py foo.py __init__.py relative.py
$ cat bar/absolute.py
from __future__ import absolute_import
import foo
$ cat bar/relative.py
import foo
$ cat foo.py
print "toplevel"
$ cat bar/foo.py
print "in bar"
$ python2.5 -c 'import bar.absolute'
toplevel
$ python2.5 -c 'import bar.relative'
in bar
Another example is here:
http://mail.python.org/pipermail/python-list/2007-January/422889.html
Peter
More information about the Python-list
mailing list