Detecting __future__ features

Steve Holden steve at holdenweb.com
Mon Jul 30 11:31:42 EDT 2007


Lawrence Oluyede wrote:
> Steven D'Aprano <steve at REMOVE.THIS.cybersource.com.au> wrote:
>> Is there any general mechanism? 
> 
> I'd just use the expected future feature and if the result is not what I
> expect (or Python raises any kind of exception, like using a keyword not
> present) I'd think I'm in the past :-)
> 
Of course if the use of the feature creates a syntax error in the 
__main__ module (as it might currently for a use of the "with" keyword 
in 2.5, for example) then there is no way to catch the exception and you 
are therefore SOL, no?

sholden at bigboy ~/Projects/Python
$ cat test11.py
with open("myfile.txt") as f:
     print l for l in f


sholden at bigboy ~/Projects/Python
$ python test11.py
test11.py:1: Warning: 'with' will become a reserved keyword in Python 2.6
   File "test11.py", line 1
     with open("myfile.txt") as f:
             ^
SyntaxError: invalid syntax


regards
  Steve
-- 
Steve Holden        +1 571 484 6266   +1 800 494 3119
Holden Web LLC/Ltd           http://www.holdenweb.com
Skype: holdenweb      http://del.icio.us/steve.holden
--------------- Asciimercial ------------------
Get on the web: Blog, lens and tag the Internet
Many services currently offer free registration
----------- Thank You for Reading -------------




More information about the Python-list mailing list