Obtaining Python version

Yinon Ehrlich yinon.me at gmail.com
Tue Aug 4 06:30:52 EDT 2009


On Aug 4, 1:19 am, 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]
>
> 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

Hi,
Easy way to test for Python version:
if sys.hexversion >= 0x2060100:
  pass

--  Yinon



More information about the Python-list mailing list