版本控制库 [英] Versioning Libraries

查看:67
本文介绍了版本控制库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

随着Python的变化和旧代码仍然需要正常工作,我想知道是否有一个标准的方法来记录哪个版本的Python解释器

代码是打算跟...共事。我知道可执行文件可能以

#!/ usr / bin / python2.3或类似的东西开头,但库和

怎么样呢?我写的软件检查

版本的翻译是不是一个好主意?


Randall Smith

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?

Randall Smith

推荐答案

Randall Smith写道:
Randall Smith wrote:
随着Python的变化和旧代码仍然需要正常工作,我想知道是否有一种标准的方法可以请注意哪个版本的Python解释器
代码可以使用。我知道可执行文件可以从
#!/ usr / bin / python2.3或类似的东西开始,但是库和
这样的呢?对于我编写的软件来检查解释器的版本是不是一个好主意?
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特别向后兼容,所以一般都是/>
来自旧版本的代码将在较新版本上保持不变
Pythons。


有一种编码解释器版本的简单方法,

但真正的问题是你为什么要这样做。如果你确实认为这是必要的,只需导入sys并检查sys.version_info的

值。很多代码都需要

a *最小* Python版本(比

检查* * *更常见的用例)包含如下代码:如果sys.hex_version [:3]< (2,3,3):

sys.exit(''需要Python 2.3.3或更高版本才能运行!'')

-Peter



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


Randall Smith写道:
Randall Smith wrote:
随着Python的变化和旧代码仍然需要正常工作,我想知道是否有标准的方法来记录哪个版本Python解释器
代码旨在使用。我知道可执行文件可以从
#!/ usr / bin / python2.3或类似的东西开始,但是库和
这样的呢?对于我编写的软件来检查解释器的版本是不是一个好主意?
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特别向后兼容,所以一般都是/>
来自旧版本的代码将在较新版本上保持不变
Pythons。


有一种编码解释器版本的简单方法,

但真正的问题是你为什么要这样做。如果你确实认为这是必要的,只需导入sys并检查sys.version_info的

值。很多代码都需要

a *最小* Python版本(比

检查* * *更常见的用例)包含如下代码:如果sys.hex_version [:3]< (2,3,3):

sys.exit(''需要Python 2.3.3或更高版本才能运行!'')

-Peter



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


Peter Hansen写道:
Peter Hansen wrote:
Randall Smith写道:
Randall Smith wrote:
随着Python的变化和旧代码仍然需要正常工作,我想知道是否有标准的方法来记录Python
解释器代码的哪个版本可以使用。我知道一个可执行文件可能以#!/ usr / bin / python2.3或类似的东西开头,但关于库等等是什么?我编写的软件检查翻译版本是不是一个好主意?
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特别向后兼容,所以一般来说代码来自旧版本将在更新的Pythons上保持不变。

有一种编码解释器版本的简单方法,
但真正的问题是你为什么要这样做那。如果您确实认为这是必要的,只需导入sys并检查sys.version_info的值。许多代码想要要求* *最小*版本的Python(比
检查* * *更常见的用例)包含这样的代码:

import sys
如果sys.hex_version [:3]< (2,3,3):
sys.exit(''需要Python 2.3.3或更高版本才能运行!'')

-Peter


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认为你的意思是:



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
import sys
sys.version_info[:3] (2, 4, 0) sys.version_info[:3] >= (2, 3, 3) True
sys.hex_version



Traceback(最近一次调用最后一次):

文件"< interactive input>",第1行,在?

AttributeError:''module''对象没有属性''hex_version''


bryan


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

bryan


这篇关于版本控制库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆