Checking Python version in a program
prestonlanders at my-deja.com
Thu Mar 2 17:48:09 CET 2000
My program Pagecast (http://pagecast.sourceforge.net) requires some
library (not language) features of Python 1.5.2.
I would like to put a semi-intelligent Python version check in the
program to give the users a meaningful error message.
What I've got so far is this:
import sys, string
required_python_version = "1.5.2"
actual_python_version = string.split(sys.version)
if actual_python_version != required_python_version:
sys.stderr.write("Sorry, Pagecast requires Python %s!\nYou seem to
have version %s.\nPlease upgrade Python (www.python.org) before running
Pagecast." % (required_python_version, actual_python_version))
However, this has the drawback that the program doesn't want to run with
the upcoming Python 1.6 (even if it is compatible.)
Does anyone have a more intelligent way to check Python versions from
within a program? I guess I could hack up something that parses the
version string further. I wish it were as simple as
if int(version) < int(required_version): spew()
but the 1.5.x scheme doesn't mesh well with that...
|| Preston Landers <prestonlanders at my-deja.com> ||
Sent via Deja.com http://www.deja.com/
Before you buy.
More information about the Python-list