Obtaining Python version

André andre.roberge at gmail.com
Mon Aug 3 18:32:10 EDT 2009


On Aug 3, 7:19 pm, John Nagle <na... at animats.com> wrote:
> This works, but it seems too cute:
>
>  >>> pyver = map(int,sys.version.split()[0].split('.'))
>  >>> print(pyver)
> [2, 6, 1]
>

You can also do:

>>> import sys
>>> sys.version_info
(2, 5, 2, 'final', 0)

or
>>> sys.version_info[:3]
(2, 5, 2)

> Is it guaranteed that the Python version string will be in a form
> suitable for that?  In other words, does "sys.version" begin
>
> N.N.N other stuff
>
> in all versions, and will it stay that way?  Are there ever
> non-numeric versions, like "3.2.rc1"?
>
>                                 John Nagle

I strongly suspect that sys.version_info would never change...

André



More information about the Python-list mailing list