[Tutor] Checking for Python version

Kent Johnson kent37 at tds.net
Tue Oct 6 16:16:55 CEST 2009


On Tue, Oct 6, 2009 at 9:59 AM, Didar Hossain <didar.hossain at gmail.com> wrote:
> Hi,
>
> I am using the following code to check for the Python version -
>
> import os
>
> t = os.sys.version_info[0:2]
> if (t[0] + t[1]) < 6:

Hmm, what would this give for Python 1.5? How about
if t < (2, 4):

>    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"
> directive.

You could check for what you actually need rather than checking the version:
try:
  staticmethod
except NameError:
  os.sys.exit("Need at least Python 2.4")

Kent


More information about the Tutor mailing list