Best way of checking for Python version

I am thinking in the lines of…

import sys
if sys.version_info.major == 3:

Do something

elif sys.version_info.major == 2:

Do something else

Anyone has any better and cleaner solution, perhaps more wxPython-like? 'Cause my lines are purely Python.

Bo�tjan Mejak wrote:

I am thinking in the lines of...

import sys
if sys.version_info.major == 3:
     # Do something
elif sys.version_info.major == 2:
     # Do something else

Anyone has any better and cleaner solution, perhaps more wxPython-like?
'Cause my lines are purely Python.

I like this approach

PY3 = sys.version_info[0] == 3

if PY3:
    doSomething()
else:
    doSomethingElse()

If you're using Phoenix then the six module has been copied into the wx.lib package, and it has that and a bunch of other stuff to help you write code that is compatible with both 2.7 and 3.

···

--
Robin Dunn
Software Craftsman

So what's wrong with *that* ?

Karsten

···

On Sun, Mar 17, 2013 at 12:47:12AM +0100, Boštjan Mejak wrote:

import sys
if sys.version_info.major == 3:
    # Do something
elif sys.version_info.major == 2:
    # Do something else

Anyone has any better and cleaner solution, perhaps more wxPython-like?

'Cause my lines are purely Python.

--
GPG key ID E4071346 @ gpg-keyserver.de
E167 67FD A291 2BEA 73BD 4537 78B9 A9F9 E407 1346