在 Python 包中添加 __author__ 的位置

Where to add __author__ in Python Packages

我正在编写一个简单的 Python 包,(目前)只有一个模块。

我应该把文档字符串和 __author__ 元属性放在哪里?它们是在 __init__.py 中还是在每个模块中?

是否有与此相关的 PEP?我只能找到通用的文档字符串,它没有回答这个问题。

老实说,如果你有的话,我会把作者放在 setup.py 文件中。这样你就不会用重复的信息污染项目中的所有文件。

但是如果你想这样做你可以按照这个结构http://web.archive.org/web/20111010053227/http://jaynes.colorado.edu/PythonGuidelines.html#module_formatting

根据PEP 8

Module level "dunders" (i.e. names with two leading and two trailing underscores) such as all , author , version , etc. should be placed after the module docstring but before any import statements except from future imports.

所以我建议将它放在导入语句之前和文档字符串之后。