[Tutor] Checking for Python version

Wayne srilyk at gmail.com
Tue Oct 6 16:42:04 CEST 2009


On Tue, Oct 6, 2009 at 9:26 AM, Christian Witts <cwitts at compuscan.co.za>wrote:

> 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?
>
>
Is there anything wrong with using this?

import sys

if sys.version < '2.4':
   sys.exit("Need at least Python 2.4")

AFAIK the string comparison is reliable
-Wayne
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20091006/785c31bb/attachment.htm>


More information about the Tutor mailing list