[英]How to automatically generate docstrings including nested functions?
How to generate automatically docs for the c_nested
function?如何为
c_nested
function 自动生成文档?
Background: I do code documentation for other developers and I would like to automatically generate a summary of all class methods included nested functions with short description (docstring).背景:我为其他开发人员编写代码文档,我想自动生成所有 class 方法的摘要,包括带有简短描述(文档字符串)的嵌套函数。
When I run help(A)
on class A
I get:当我在 class
A
上运行help(A)
时,我得到:
Help on class A in module __main__:
class A(builtins.object)
| A(a)
|
| doc A
|
| Methods defined here:
|
| __init__(self, a)
| Initialize self. See
|
| b_method(self)
| doc b_method
Requested output: c_nested()
with docstring: (Docs could be printed event with script, it doesn't need to be printed with pydoc help.)请求的 output:
c_nested()
with docstring: (文档可以用脚本打印事件,不需要用 pydoc 帮助打印。)
Help on class A in module __main__:
class A(builtins.object)
| A(a)
|
| doc A
|
| Methods defined here:
|
| __init__(self, a)
| Initialize self. See
|
| b_method(self)
| doc b_method
|
| c_nested()
| doc c_nested
Class example: Class 示例:
class A:
""" doc A """
def __init__(self,a):
self.a = a
def b_method(self):
""" doc b_method """
def c_nested():
"""doc c_nested """
pass
return c_nested()
Local functions are not publicly visible, so their docstring won't be included in the help.本地函数不公开可见,因此它们的文档字符串不会包含在帮助中。
If you want the function to be shown in the help, make it a module-level function or a method of the class.如果您希望 function 在帮助中显示,请将其设为模块级 function 或 class 的方法。
See also Are docstrings for internal functions (python) necessary?另请参阅是否需要内部函数 (python) 的文档字符串?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.