gpt4 book ai didi

python - 常见的Python文件头格式是什么?

转载 作者:行者123 更新时间:2023-12-05 07:48:54 26 4
gpt4 key购买 nike

我在有关 Python 编码指南的文档中遇到了 Python 源文件的以下 header 格式:

#!/usr/bin/env python

"""Foobar.py: Description of what foobar does."""

__author__ = "Barack Obama"
__copyright__ = "Copyright 2009, Planet Earth"

这是 Python 世界中 header 的标准格式吗?我可以在标题中放置哪些其他字段/信息?Python 大师分享您关于良好 Python 源头文件的指南:-)

最佳答案

它是 Foobar 模块的所有元数据。

第一个是模块的docstring,已经在Peter's answer中解释过了。 .

How do I organize my modules (source files)? (Archive)

The first line of each file shoud be #!/usr/bin/env python. This makes it possible to run the file as a script invoking the interpreter implicitly, e.g. in a CGI context.

Next should be the docstring with a description. If the description is long, the first line should be a short summary that makes sense on its own, separated from the rest by a newline.

All code, including import statements, should follow the docstring. Otherwise, the docstring will not be recognized by the interpreter, and you will not have access to it in interactive sessions (i.e. through obj.__doc__) or when generating documentation with automated tools.

Import built-in modules first, followed by third-party modules, followed by any changes to the path and your own modules. Especially, additions to the path and names of your modules are likely to change rapidly: keeping them in one place makes them easier to find.

Next should be authorship information. This information should follow this format:

__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"

Status should typically be one of "Prototype", "Development", or "Production". __maintainer__ should be the person who will fix bugs and make improvements if imported. __credits__ differs from __author__ in that __credits__ includes people who reported bug fixes, made suggestions, etc. but did not actually write the code.

Here您有更多信息,列出 __author____authors____contact____copyright____license____deprecated____date____version__ 作为识别的元数据。

关于python - 常见的Python文件头格式是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37989422/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com