Python 库中的命名约定
我正在 python 包中实现一个搜索算法(我们称之为 MyAlg)。 由于该算法非常复杂,因此该包必须包含一个用于算法选项的辅助类。 目前我正在自己开发整个包(我不是程序员),但是我预计稍后会有 1-2 名程序员加入该项目。 这将是我第一个涉及外部程序员的项目。 因此,为了让他们的生活更轻松,我应该如何命名这个类:Options、OptionsMyAlg、MyAlgOptions 或其他名称?
除了 http://www.joelonsoftware.com/ 之外,您建议我在本主题中阅读什么内容文章/Wrong.html?
谢谢 尤里 [从此处交叉发布:http://discuss.joelonsoftware.com/default。 asp?design.4.684669.0 将更新两个地方的答案]
I'm implementing a search algorithm (let's call it MyAlg) in a python package. Since the algorithm is super-duper complicated, the package has to contain an auxiliary class for algorithm options. Currently I'm developing the entire package by myself (and I'm not a programmer), however I expect 1-2 programmers to join the project later. This would be my first project that will involve external programmers. Thus, in order to make their lifes easier, how should I name this class: Options, OptionsMyAlg, MyAlgOptions or anything else?
What would you suggest me to read in this topic except for http://www.joelonsoftware.com/articles/Wrong.html ?
Thank you
Yuri
[cross posted from here: http://discuss.joelonsoftware.com/default.asp?design.4.684669.0 will update the answers in both places]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我建议您阅读 PEP8 (Python 代码的样式指南)。
I suggest you read PEP8 (styleguide for Python code).
只需将其命名为
Options
就可以了。 Python 标准库通常遵循这样的理念:命名空间使不同的包能够轻松且易于管理地拥有相同名称的事物。 例如,open
既是os
模块中的内置函数,又是os
模块中的函数,几个不同的模块定义了Error
异常类,等等。这就是为什么
from some_module import *
通常被认为是不好的形式,因为它让人不清楚你的代码引用的是哪个open
等。Just naming it
Options
should be fine. The Python standard library generally takes the philosophy that namespaces make it easy and manageable for different packages to have identically named things. For example,open
is both a builtin and a function in theos
module, several different modules define anError
exception class, and so on.This is why it's generally considered bad form to say
from some_module import *
since it makes it unclear to whichopen
your code refers, etc.如果所有内容都适合一个文件,则将该类命名为 Options。 然后你的用户可以写:
注意另一个答案中引用的Python风格指南建议包应该用全部小写字母命名。
If it all fits in one file, name the class Options. Then your users can write:
Note the Python Style Guide referenced in another answer suggests that packages should be named with all lowercase letters.