easiest way to check python version?

Scott David Daniels Scott.Daniels at Acm.Org
Wed Jun 10 17:09:15 CEST 2009


John Machin wrote:
> On Jun 10, 9:01 pm, dmitrey <dmitrey.kros... at scipy.org> wrote:
>> hi all,
>> what is easiest way  to check python version (to obtain values like
>> 2.4, 2.5, 2.6, 3.0 etc) from Python env?
...
> "easiest" depends on purpose; e.g. version for display or for logging
> exactly what the customer is running. version_info (or a prefix of it)
> is the best for things like conditional imports etc
> 
> E.g.
> py_version = sys.version_info[:2]
> if py_version == (2, 3):
>     from sets import Set as set

Note also that the definition of tuple comparison help you here:

     if (2, 1, 1) < sys.version_info < (2, 3):
         ...
     elif (2, 5) <= sys.version_info <= (2, 6, 2, 'final'):
         ...
     else:
         print('Untested')

--Scott David Daniels
Scott.Daniels at Acm.Org




More information about the Python-list mailing list