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


Groups > comp.lang.python > #102170 > unrolled thread

how to get python version ?

Started bynamenobodywants@gmail.com
First post2016-01-27 21:21 -0800
Last post2016-01-28 17:02 +0000
Articles 5 — 5 participants

Back to article view | Back to comp.lang.python


Contents

  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

#102170 — how to get python version ?

Fromnamenobodywants@gmail.com
Date2016-01-27 21:21 -0800
Subjecthow to get python version ?
Message-ID<76180516-f465-4fde-a1c4-920c91036623@googlegroups.com>
hi

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

peace
stm

[toc] | [next] | [standalone]


#102171

FromBen Finney <ben+python@benfinney.id.au>
Date2016-01-28 16:34 +1100
Message-ID<mailman.42.1453959261.2338.python-list@python.org>
In reply to#102170
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

[toc] | [prev] | [next] | [standalone]


#102172

FromRustom Mody <rustompmody@gmail.com>
Date2016-01-27 21:48 -0800
Message-ID<4ae9a6e8-c578-4c7d-b975-0640be5555e6@googlegroups.com>
In reply to#102170
On Thursday, January 28, 2016 at 10:51:17 AM UTC+5:30, namenob...@gmail.com wrote:
> hi
> 
> 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
> 
> peace
> stm

You want this??
https://docs.python.org/3.5/library/platform.html

[toc] | [prev] | [next] | [standalone]


#102174

FromChris Angelico <rosuav@gmail.com>
Date2016-01-28 18:30 +1100
Message-ID<mailman.44.1453966228.2338.python-list@python.org>
In reply to#102170
On Thu, Jan 28, 2016 at 4:21 PM,  <namenobodywants@gmail.com> wrote:
> 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

Check out sys.version and sys.version_info - are they what you're after?

ChrisA

[toc] | [prev] | [next] | [standalone]


#102195

FromRob Gaddi <rgaddi@highlandtechnology.invalid>
Date2016-01-28 17:02 +0000
Message-ID<n8dhid$hpv$1@dont-email.me>
In reply to#102170
namenobodywants@gmail.com wrote:

> hi
>
> 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
>
> peace
> stm

Since everyone else has answered the question you asked, let me answer
the question I think you might have wanted to ask instead.

If what you're trying to determine is simply whether you're running
under Python 2 or 3, then the six package has booleans for six.PY2 and
six.PY3, so you can say things like:

  if six.PY2:
    def my_fn():
      ...
  else:
    def my_fn():
      ...

Note that checking compatibility this way (calling Python 2 "the weird
one") rather than "if six.PY3" will keep your code compatible in the
future as well.

Bringing in an entire extra package just for one boolean seems
excessive, but if you're actually making that check it's because you've
got a bunch of 2/3 compatibility crap you're having to work out; six
will help will all of that too.

-- 
Rob Gaddi, Highland Technology -- www.highlandtechnology.com
Email address domain is currently out of order.  See above to fix.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web