import sys
if sys.version_info < (2, 4):
raise "must use python 2.5 or greater"
else:
# syntax error in 2.4, ok in 2.5
x = 1 if True else 2
print x
在2.4版本下运行,我希望得到这个结果。
$ ~/bin/python2.4 tern.py
must use python 2.5 or greater
而不是这个结果:
$ ~/bin/python2.4 tern.py
File "tern.py", line 5
x = 1 if True else 2
^
SyntaxError: invalid syntax
(Channeling for a coworker.)