Detecting __future__ features

Steven D'Aprano steve at REMOVE.THIS.cybersource.com.au
Mon Jul 30 08:29:28 EDT 2007


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 use"
else:
    print "true division in use"


I could even do this:

from keyword import keyword
if keyword("with"):
    print "with statement enabled"
else:
    print "with statement not enabled"

(I don't especially care whether the feature in question has been enabled
via an explicit call to import, or because it has become the default.)

Is there any general mechanism? 


-- 
Steven.




More information about the Python-list mailing list