by dec0dedab0de · 5y ago · 0 comments
import sys
if sys.version_info.major < 3:
raise Exception("this script requires python version >= 3")
plus an extra line or two if you're worried about minor versions. > cat test.py
import sys
if sys.version_info.major < 3:
raise Exception("this script requires python version >= 3")
print(f"test")
> python2 test.py
File "test.py", line 5
print(f"test")
^
SyntaxError: invalid syntax
Doesn't seem that simple from __future__ import absolute_import, division, print_function, unicode_literals
This will give you syntax much closer to Python 3 in Python 2.7. The remaining differences can be papered over with function and class helpers. Well, except for metaclasses, but I doubt you'd have need for those in a single-file script.print(f"whee")
And run it with python2, or a python3 < 3.6.