在一篇关于Python编码指南的文档中,我遇到了Python源文件的以下标题格式:
#!/usr/bin/env python
"""Foobar.py: Description of what foobar does."""
__author__ = "Barack Obama"
__copyright__ = "Copyright 2009, Planet Earth"
这是Python世界中标题的标准格式吗?
在一篇关于Python编码指南的文档中,我遇到了Python源文件的以下标题格式:
#!/usr/bin/env python
"""Foobar.py: Description of what foobar does."""
__author__ = "Barack Obama"
__copyright__ = "Copyright 2009, Planet Earth"
这是Python世界中标题的标准格式吗?
这都是Foobar
模块的元数据.
第一个是模块的docstring
,已经在Peter's answer中解释过了.
如何组织我的模块(源文件)?(档案)
The first line of each file shoud be 100.这使得可以将文件作为隐式调用解释器的脚本运行,例如在CGI上下文中.
100如果描述很长,第一行应该是一个简短的摘要,它本身就有意义,用一个新行与其余部分隔开.
All code, including import statements, should follow the docstring.否则,解释器将无法识别文档字符串,并且您将无法在交互式会话中(即通过
obj.__doc__
)或在使用自动化工具生成文档时访问它.Import built-in modules first, followed by third-party modules, followed by any changes to the path and your own modules.尤其是,模块路径和名称的添加可能会迅速改变:将它们放在一个地方会更容易找到.
Next should be authorship information.此信息应遵循以下格式:
__author__ = "Rob Knight, Gavin Huttley, and Peter Maxwell" __copyright__ = "Copyright 2007, The Cogent Project" __credits__ = ["Rob Knight", "Peter Maxwell", "Gavin Huttley", "Matthew Wakefield"] __license__ = "GPL" __version__ = "1.0.1" __maintainer__ = "Rob Knight" __email__ = "rob@spot.colorado.edu" __status__ = "Production"
状态通常应该是"原型"、"开发"或"生产"之一.
__maintainer__
应该是谁将修复错误,并作出改进,如果进口.__credits__
与__author__
的不同之处在于,__credits__
包括报告错误修复、提出建议等但实际上并没有编写代码的人.
Here您有更多信息,将__author__
、__authors__
、__contact__
、__copyright__
、__license__
、__deprecated__
、__date__
和__version__
列为可识别的元数据.