[Tutor] Checking for Python version
tmz at pobox.com
Tue Oct 6 17:02:22 CEST 2009
Christian Witts wrote:
> Your version will fail if the person is running Python 3.0, 3.1 up
> until the 3.3 series which is not good. Neater looking (imo) code
> from sys import version_info, exit
> if version_info == 1 or (version_info == 2 and version_info < 4):
> exit("Please upgrade to Python 2.4 or greater.")
This would fail on python < 2.0, as version_info is not available. So
you'd want to catch that, if you want to gracefully handle ancient
versions of python. You could also just compare the version_info
This is a bit ugly, but it works at least back to 1.5.2:
min_version = '2.4'
upgrade_msg = 'Please upgrade to Python %s or greater' % min_version
min = tuple(map(int, min_version.split('.')))
ver = sys.version_info[:3]
if ver < min:
I don't have any python 3.x systems to test though.
Todd OpenPGP -> KeyID: 0xBEAF0CE3 | URL: www.pobox.com/~tmz/pgp
Suppose I were a member of Congress, and suppose I were an idiot. But,
I repeat myself.
-- Mark Twain
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Size: 542 bytes
Desc: not available
More information about the Tutor