Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #102171

Re: how to get python version ?

From Ben Finney <ben+python@benfinney.id.au>
Newsgroups comp.lang.python
Subject Re: how to get python version ?
Date 2016-01-28 16:34 +1100
Message-ID <mailman.42.1453959261.2338.python-list@python.org> (permalink)
References <76180516-f465-4fde-a1c4-920c91036623@googlegroups.com>

Show all headers | View raw


namenobodywants@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

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

how to get python version ? namenobodywants@gmail.com - 2016-01-27 21:21 -0800
  Re: how to get python version ? Ben Finney <ben+python@benfinney.id.au> - 2016-01-28 16:34 +1100
  Re: how to get python version ? Rustom Mody <rustompmody@gmail.com> - 2016-01-27 21:48 -0800
  Re: how to get python version ? Chris Angelico <rosuav@gmail.com> - 2016-01-28 18:30 +1100
  Re: how to get python version ? Rob Gaddi <rgaddi@highlandtechnology.invalid> - 2016-01-28 17:02 +0000

csiph-web