473,440 Members | 1,782 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,440 software developers and data experts.

Strange __future__ behavior in Python 2.5

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.

Sep 23 '06 #1
3 1227
md******@gmail.com wrote:
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:
*snip*
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.

Only one "from __future__" can be imported per line.

So,
from __future__ import foo
from __future__ import bar
etc.

It will only import the first if you give multiple.

Why this is, I don't know.

Sep 23 '06 #2
md******@gmail.com wrote:
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.
This is a bug and has now been fixed in the SVN repo.
Thanks for bringing it up.

Georg
Sep 24 '06 #3

Georg Brandl wrote:
This is a bug and has now been fixed in the SVN repo.
Thanks for bringing it up.

Ouch, I feel bad now. I've been noticing this behavior since 2.5B1 but
I didn't realize it was a bug.

Sep 24 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Logan | last post by:
Is there a list with all 'from __future__ import ...' statements (which lists all the statements, in which version of Python the feature was introduced and in which version of Python it will become...
0
by: John Hunter | last post by:
I have a class that uses some extension code I have written and I am trying to track down some memory leaks, which I presume to be in my extension code. The class is question is in a python...
7
by: Ron Adam | last post by:
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) on win 32 ...
5
by: rconradharris | last post by:
A co-worker of mine came across some interesting behavior in the Python interpreter today and I'm hoping someone more knowledgeable in Python internals can explain this to me. First, we create...
11
by: Steven D'Aprano | last post by:
How would one tell at runtime if a particular feature has been enabled by the "from __future__ import thing" statement? For example, I can do this: if 1/2 == 0: print "classic division in...
7
by: samslists | last post by:
Am I the only one that thinks this would be useful? :) I'd really like to be able to use python 3.0's print statement in 2.x. Is this at least being considered as an option for 2.6? It seems...
1
by: Malcolm Greene | last post by:
Is there any consensus on what "from __future__ import" options developers should be using in their Python 2.5.2 applications? Is there a consolidated list of "from __future__ import" options to...
0
by: Tim Golden | last post by:
Malcolm Greene wrote: Well, that bit's easy: import __future__ print __future__.all_feature_names TJG
2
by: karthikbalaguru | last post by:
Hi, I am new to python, Kindly suggest to resolve a problem with a python file. What does the below error refer to ? I use Redhat 9.0, python-2.2.2-26, python-devel-2.2.2-26 and db4-4.0.14-20....
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.