私は多くの小さな関数を備えたモジュールに取り組んでいますが、そのdocstringはかなり長くなる傾向があります。実際のコードを少し見つけるために長いdocstringを絶えずスクロールしなければならないので、docstringはモジュールでの作業を苛立たせます。
docstringをドキュメント化する関数から分離する方法はありますか?ファイルの最後にあるdocstringをコードから離して指定できるようにしたいのですが、さらに良いのは、別のファイルで指定できるようにすることです。
関数のdocstringは、特別な属性として使用できます__doc__。
>>> def f(x):
... "return the square of x"
... return x * x
>>> f.__doc__
'return the square of x'
>>> help(f)
(help page with appropriate docstring)
>>> f.__doc__ = "Return the argument squared"
>>> help(f)
(help page with new docstring)
とにかく、それはテクニックを示しています。実際には、次のことができます。
def f(x):
return x * x
f.__doc__ = """
Return the square of the function argument.
Arguments: x - number to square
Return value: x squared
Exceptions: none
Global variables used: none
Side effects: none
Limitations: none
"""
...またはdocstringに入れたいものは何でも。