check interpreter version before running script

Josef Meile jmeile at hotmail.com
Tue Apr 5 09:49:29 EDT 2005


> Is there a recommended or 'Best Practices' way of checking the version 
> of python before running scripts? I have scripts that use the os.walk() 
> feature (introduced in 2.3) and users running 2.2 who get errors. 
> Instead of telling them, 'Upgrade you Python Install, I'd like to use 
> sys.version or some other way of checking before running.
> 
> Whatever I do, I need it to work on Linux, Mac and Windows.
> 
> I thought of sys.version... but getting info out of it seems awkward to 
> me. First 5 chars are '2.4.1' in string format have to split it up and 
> convert it to ints to do proper checking, etc. It doesn't seem that 
> sys.version was built with this type of usage in mind. So, what is the 
> *best* most correct way to go about this?
> 
What's about:
 >>> import sys
 >>> print sys.version_info
(2, 1, 3, 'final', 0)

Regards,
Josef




More information about the Python-list mailing list