将文件版本与模块名称分离。 [英] Decoupling the version of the file from the name of the module.

查看:56
本文介绍了将文件版本与模块名称分离。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一个尝试使用Python的新手。我想逐步开发一个名为''circle''的模块。

。问题是现在使用文件名

有两个目的。跟踪模块的版本号和名称

。因此,当我开发我的文件的第一个版本时,我将

称为circle_a.py。然后模块的名称自动变为
变为circle_a。但是当我开发下一个增量并调用我的

文件circle_b.py时,模块名称也会发生变化。


基本上我想要解除我的版本文件名为

模块。


有没有*简单的方法摆脱这种困境。

I''m a newbie experimenting with Python. I want to incrementally develop
a module called ''circle''. The problem is now that the file name is used
for two purposes. To keep track of the version number and as the name
for the module. So when I develop the first version of my file I have
to call it circle_a.py. The name of the module then automatically
becomes circle_a. But when I develop the next increment and call my
file circle_b.py the module name changes as well.

Basically I want to decouple the version of my file from the name of
the module.

Is there a *simple* way out of this dilemma.

推荐答案

bo ******* @ yahoo.com 写道:
我是一个尝试使用Python的新手。我想逐步开发一个名为''circle''的模块。现在的问题是文件名用于两个目的。跟踪模块的版本号和名称
。因此,当我开发文件的第一个版本时,我将其称为circle_a.py。然后模块的名称自动变为circle_a。但是当我开发下一个增量并调用我的
文件circle_b.py时,模块名称也会发生变化。

基本上我想将我的文件版本与
模块。

有没有简单的方法摆脱这种困境。
I''m a newbie experimenting with Python. I want to incrementally develop
a module called ''circle''. The problem is now that the file name is used
for two purposes. To keep track of the version number and as the name
for the module. So when I develop the first version of my file I have
to call it circle_a.py. The name of the module then automatically
becomes circle_a. But when I develop the next increment and call my
file circle_b.py the module name changes as well.

Basically I want to decouple the version of my file from the name of
the module.

Is there a *simple* way out of this dilemma.




您有两种选择:


1-只需删除名称中的版本号(重点是什么)和

在模块中定义__version__属性,这就是什么通常已完成。

2-创建一个名为circle.py的包装器模块。其内容将是

类似于from your_current_module_with_version

import *


我强烈要求建议第一个选择,将

版本号放入模块的文件名中是没有意义的。



You have two choices:

1- Just get rid of the version number in the name (what''s the point) and
define a __version__ attribute in the module, that''s what is usually done.
2- create a wrapper module called "circle.py" whose content will be
something along the lines of "from your_current_module_with_version
import *"

I''d strongly suggest the first choice, there is no point in giving the
version number into the file name of a module.


bo ******* @ yahoo.com 写道:
我是一个尝试使用Python的新手。我想逐步开发一个名为''circle''的模块。现在的问题是文件名用于两个目的。跟踪模块的版本号和名称
。因此,当我开发文件的第一个版本时,我将其称为circle_a.py。然后模块的名称自动变为circle_a。但是当我开发下一个增量并调用我的
文件circle_b.py时,模块名称也会发生变化。

基本上我想将我的文件版本与
模块。

有没有简单的方法摆脱这种困境。
I''m a newbie experimenting with Python. I want to incrementally develop
a module called ''circle''. The problem is now that the file name is used
for two purposes. To keep track of the version number and as the name
for the module. So when I develop the first version of my file I have
to call it circle_a.py. The name of the module then automatically
becomes circle_a. But when I develop the next increment and call my
file circle_b.py the module name changes as well.

Basically I want to decouple the version of my file from the name of
the module.

Is there a *simple* way out of this dilemma.




我建议只命名文件circle.py ,并定义一些东西

就像一个名为__version__的变量,或者在模块顶部的
顶部可能是__revision__。然后,你可以,我不知道,备份你的旧版本

其他文件名或其他东西。


或者,如果你真的想做没错,你可以安装Subversion。 :-)


-Kirk McDonald



I would recommend just naming the file circle.py, and defining something
like a variable named __version__ or maybe __revision__ at the top of
the module. Then you can, I don''t know, back up your old versions to
other filenames or something.

Or, if you really want to do this right, you could install Subversion. :-)

-Kirk McDonald


bo ******* @ yahoo.com 写道:
基本上我想将我的文件版本与
模块的名称分离。

有没有简单的方法摆脱这种困境。
Basically I want to decouple the version of my file from the name of
the module.

Is there a *simple* way out of this dilemma.




实际上,你应该使用源控制系统。这是一个程序,

跟踪程序中不同版本的文件。当你的文件中有一个

达到稳定状态时,你会检查它。到一个

源存储库,然后记住该版本。然后你继续

编辑文件。之后,如果需要,您可以从存储库中恢复旧版本




源代码管理是唯一理智的方式来完成你的工作尝试做。

乱搞重命名文件以保存旧版本,因为你在做b $ b,只适用于非常小的短期项目。那个计划

会让你在短时间内发疯。


SubVersion( http://subversion.tigris.org )是一个流行的源代码控制

系统,可能不是最好的,但与一些较老的广泛使用

。我个人会选择这个,因为我有一些经验

,但它并不理想。即使您不选择使用它,您也可以阅读其在线文档,以了解这些程序试图解决的问题类型。


有一个名为Codeville的新版本,用Python编写,我没有尝试过
。还有很多其他的我不想再试图

列表。哪一个最好的是宗教战争的话题,比如

最佳编辑。或最好的语言。只需选择一个你喜欢的和

坚持下去。



Really, you should use a source control system. That''s a program that
tracks the different versions of the files in your program. When one
of your files reaches a state of stability, you "check it in" to a
source repository which then remembers that version. You then go on
editing the file in place. Later, you can restore the old version
from the repository if you need to.

Source control is the only sane way to do what you''re trying to do.
Messing around with renaming files to save old versions, as you''re
doing, only works for very small, short-lived projects. That scheme
will drive you crazy in short order.

SubVersion (http://subversion.tigris.org) is a popular source control
system, maybe not the best, but compatible with some older widely used
ones. I''d personally choose this one because I have some experience
with it, but it''s not ideal. Even if you don''t choose to use it, you
might read its online docs, to get a sense of what kinds of problems
these programs try to solve.

There''s a newer one called Codeville, written in Python, that I
haven''t tried. There are numerous others I won''t bother trying to
list. Which one is best is the topic of religious wars, like "the
best editor" or "the best language". Just pick one that you like and
stick with it.


这篇关于将文件版本与模块名称分离。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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