[Tutor] Checking for Python version

Dave Angel davea at ieee.org
Tue Oct 6 17:04:02 CEST 2009


Didar Hossain 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:
>     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.
>
> Is there a prettier way or is this fine?
>
> Regards,
> Didar
>
>   
How about
  if sys.version_info < (2,4):

Incidentally, your particular approach has the problem of failing for 
3.1.  Perhaps that was intended, but it wasn't obvious.

DaveA


More information about the Tutor mailing list