Any check to see if the code written is in python 2.7 or 3 and above?

為{幸葍}努か 提交于 2019-11-29 03:00:43

Attempt to compile it. If the script uses syntax specific to a version then the compilation will fail.

$ python2 -m py_compile foo.py
$ python3 -m py_compile foo.py

add this line to the file:

help()

this should automatically print the version along with the default help interface. remember to remove it later.

Use this in your code:

import platform
print platform.python_version()

outputs a string: 2.7.10

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!