Detecting __future__ features

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

Lawrence Oluyede wrote:
> Steven D'Aprano <steve at> 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
with open("myfile.txt") as f:
     print l for l in f

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

Steve Holden        +1 571 484 6266   +1 800 494 3119
Holden Web LLC/Ltd 
Skype: holdenweb
--------------- 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