Obtaining Python version

J

John Nagle

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
 
A

André

This works, but it seems too cute:

 >>> pyver = map(int,sys.version.split()[0].split('.'))
 >>> print(pyver)
[2, 6, 1]

You can also do:
(2, 5, 2, 'final', 0)

or
(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é
 
J

Jan Kaliszewski

04-08-2009 o 00:19:22 John Nagle said:
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"?

Why not to use:

sys.version_info

"A tuple containing the five components of the version number:
major, minor, micro, releaselevel, and serial. All values except
releaselevel are integers; the release level is 'alpha', 'beta',
'candidate', or 'final'. The version_info value corresponding to
the Python version 2.0 is (2, 0, 0, 'final', 0)."

http://docs.python.org/library/sys.html#sys.version_info

Cheers,
*j
 
Y

Yinon Ehrlich

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,274
Messages
2,571,366
Members
48,055
Latest member
RacheleCar

Latest Threads

Top