Strange __future__ behavior in Python 2.5

mdsteele at gmail.com mdsteele at gmail.com
Sat Sep 23 16:51:29 EDT 2006


My understanding of the __future__ statement is that you may say
something like:

from __future__ import foo, bar

to enable more than one feature.  However, this does not seem to be
working properly in 2.5; it behaves as expected when typed into the
interactive interpreter, but not when it is in a module.  When I try to
import the following module:

from __future__ import with_statement, division, absolute_import
def bar():
    print 5/3
    with open('asdf') as f:
        for line in f: print line.strip()

I get a warning that 'with' will soon be a reserved keyword, and a
SyntaxError on the line with the with statement, so obviously, the
__future__ statement is not working.  When I change the first line to:

from __future__ import with_statement
from __future__ import division,absolute_import

then the with statement works fine.  However, the true division also
works fine, so apparently making multiple __future__ imports on one
line works for division, but not for with_statement.

Is this a bug, or am I misunderstanding something?  I'm using the final
release of Python 2.5 (r25:51918, Sep 19 2006, 08:49:13) on Mac OS X.




More information about the Python-list mailing list