how to get python version ?
Ben Finney
ben+python at benfinney.id.au
Thu Jan 28 00:34:12 EST 2016
namenobodywants at gmail.com writes:
> is there something analogous to sys.platform that lets you get the
> version of python you're using? sorry if the question is too
> see-spot-run. thanks if you can help
The same ‘sys’ module provides many other ways to interrogate the
running Python system <URL:https://docs.python.org/3/library/sys.html>.
For the running version of Python, you want ‘sys.version_info’::
>>> import sys
>>> sys.version
'2.7.11 (default, Jan 11 2016, 21:04:40) \n[GCC 5.3.1 20160101]'
>>> type(sys.version)
<type 'str'>
>>> sys.version_info
sys.version_info(major=2, minor=7, micro=11, releaselevel='final', serial=0)
>>> type(sys.version_info)
<type 'sys.version_info'>
>>> sys.version_info > (3, 1)
False
>>> sys.version_info > (2, 5)
True
The ‘sys.version’ object is a human-readable string. If you actually
want to do comparisons, use ‘sys.version_info’ for its much more
fine-grained structure.
--
\ “If you can't annoy somebody there is little point in writing.” |
`\ —Kingsley Amis |
_o__) |
Ben Finney
More information about the Python-list
mailing list