Add conditions in code depending on python version
python
Solution
You're on the wrong track here, on several counts. First, don't check for versions, check for features. The link @dave you in his comment does a good job of explaining that.
Second, if you did check for versions, and even if there weren't multiple spelling errors, this wouldn't work at all:
if(os.python.version<3.0):
from _future_ import print, super
A `__future__` statement can be preceded only by the module docstring, blank lines, comment lines, and other `__future__` statements. It cannot appear anywhere else - you'll just get a syntax error if you try.
Third, for the example you gave, checking anything is pointless. Near the top of the file,
from __future__ import print_function
is fine in both Python 2.7 and Python 3. In Python 3 it simply has no effect.
Problem
I am currently writing some code on python 3.3. Unfortunately some of the plugins I rely on are not yet compatible with Python3 and I need to switch back to Python2.7. In order to avoid refactoring all the code, I would like to do something like ``` if(os.python.version<3.0): from _future_ import print, super ``` What is the proper way of doing this