Python でモジュールを文書化するにはどうすればよいですか?
-
09-06-2019 - |
質問
それでおしまい。関数またはクラスを文書化したい場合は、定義の直後に文字列を置きます。例えば:
def foo():
"""This function does nothing."""
pass
しかし、モジュールについてはどうでしょうか?何を文書化するにはどうすればよいですか ファイル.py そうですか?
解決
パッケージの場合は、次のように文書化できます。 __init__.py
。モジュールの場合は、モジュール ファイルに docstring を簡単に追加できます。
すべての情報はここにあります: http://www.python.org/dev/peps/pep-0257/
他のヒント
docstring を モジュールの最初のステートメント.
"""
Your module's verbose yet thorough docstring.
"""
import foo
# ...
パッケージの場合は、docstring を次の場所に追加できます。 __init__.py
.
ここにあります Google スタイルの Python ドキュメント文字列の例 モジュールを文書化する方法について。基本的には、モジュールに関する情報、その実行方法、モジュール レベルの変数と ToDo 項目のリストに関する情報があります。
"""Example Google style docstrings.
This module demonstrates documentation as specified by the `Google
Python Style Guide`_. Docstrings may extend over multiple lines.
Sections are created with a section header and a colon followed by a
block of indented text.
Example:
Examples can be given using either the ``Example`` or ``Examples``
sections. Sections support any reStructuredText formatting, including
literal blocks::
$ python example_google.py
Section breaks are created by resuming unindented text. Section breaks
are also implicitly created anytime a new section starts.
Attributes:
module_level_variable1 (int): Module level variables may be documented in
either the ``Attributes`` section of the module docstring, or in an
inline docstring immediately following the variable.
Either form is acceptable, but the two should not be mixed. Choose
one convention to document module level variables and be consistent
with it.
Todo:
* For module TODOs
* You have to also use ``sphinx.ext.todo`` extension
.. _Google Python Style Guide:
http://google.github.io/styleguide/pyguide.html
"""
module_level_variable1 = 12345
def my_function():
pass
...
...
まったく同じ方法で行います。モジュールの最初のステートメントとして文字列を入力します。
簡単です。モジュールの先頭に docstring を追加するだけです。
所属していません StackOverflow