Versioning Libraries

Bryan belred1 at yahoo.com
Thu Dec 2 21:43:39 EST 2004


Peter Hansen wrote:
> Randall Smith wrote:
> 
>> As Python changes and old code still needs to work properly, I wonder 
>> if there is a standard way to note which version of the Python 
>> interpreter code is intended to work with.  I know that an executable 
>> may begin with #!/usr/bin/python2.3 or something similar, but what 
>> about libraries and such?  Would it be a good idea for the software I 
>> write to check for the version of the interpreter?
> 
> 
> Python is exceptionally backwards compatible, so generally
> code from an older version will run unchanged on newer
> Pythons.
> 
> There is a simple way of encoding a version of the interpreter,
> but the real question is why would you want to do that.  If
> you really think it's necessary, just import sys and check the
> value of sys.version_info.  Lots of code which wants to require
> a *minimum* version of Python (a far more common use case than
> checking for a *maximum*) contains code like this:
> 
> import sys
> if sys.hex_version[:3] < (2, 3, 3):
>     sys.exit('Requires Python 2.3.3 or later to run!')
> 
> 
> -Peter

i think you meant something this:

 >>> import sys
 >>> sys.version_info[:3]
(2, 4, 0)
 >>> sys.version_info[:3] >= (2, 3, 3)
True

 >>> sys.hex_version
Traceback (most recent call last):
   File "<interactive input>", line 1, in ?
AttributeError: 'module' object has no attribute 'hex_version'

bryan



More information about the Python-list mailing list