check interpreter version before running script

rbt rbt at athop1.ath.vt.edu
Tue Apr 5 08:57:12 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?

Thanks,

rbt



More information about the Python-list mailing list