Convert a Python string version (e.g., "2.5.1", "1.3", "2.6a3") to a
numeric version that can meaningfully be compared with the standard
sys module's sys.hexversion value.
For example, here's the usual way to ensure that your program is running
under Python 2.5.1 or better:
import sys
if sys.hexversion < 0x020501f0:
raise RuntimeError, 'This program requires Python 2.5.1 or better'
Here's how you'd use python_version() to do the same thing (in an
arguably more readable way):
import sys
from grizzled.sys import python_version
if sys.hexversion < python_version("2.5.1"):
raise RuntimeError, 'This program requires Python 2.5.1 or better'
- Parameters:
version (str) - string Python version to convert to binary
- Returns: int
- corresponding integer Python version
- Raises:
ValueError - version isn't of the form "x", or "x.y" or
"x.y.z"
|