How can I check what version of the Python Interpreter is interpreting my script?
相关问题
- how to define constructor for Python's new Nam
- streaming md5sum of contents of a large remote tar
- How to get the background from multiple images by
- Evil ctypes hack in python
- Correctly parse PDF paragraphs with Python
To see a MSDOS script to check the version before running the Python interpreter (to avoid Python version syntax exceptions) See solution:
How can I check for Python version in a program that uses new language features?
and
MS script; Python version check prelaunch of Python module http://pastebin.com/aAuJ91FQ (script likely easy to convert to other OS scripts.)
Here's a short commandline version which exits straight away (handy for scripts and automated execution):
Or just the major, minor and micro:
Like Seth said, the main script could check
sys.version_info
(but note that that didn't appear until 2.0, so if you want to support older versions you would need to check another version property of the sys module).But you still need to take care of not using any Python language features in the file that are not available in older Python versions. For example, this is allowed in Python 2.5 and later:
but won't work in older Python versions, because you could only have except OR finally match the try. So for compatibility with older Python versions you need to write:
With
six
module, you can do it by:The simplest way
Just type python in your terminal and you can see the version as like following
sys.version gives you what you want, just pick the first number :)