[Tutor] Checking for Python version
cwitts at compuscan.co.za
Tue Oct 6 16:26:23 CEST 2009
Didar Hossain wrote:
> I am using the following code to check for the Python version -
> import os
> t = os.sys.version_info[0:2]
> if (t + t) < 6:
> os.sys.exit("Need at least Python 2.4")
> del t
> This snippet is put at the beginning of the single script file before
> the rest of the code.
> I need to check for the minimum specific version because I am using
> the "@staticmethod"
> Is there a prettier way or is this fine?
> Tutor maillist - Tutor at python.org
> To unsubscribe or change subscription options:
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 below.
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.")
More information about the Tutor