我有以下功能:
def my_func():
"""My docstring is both funny and informative"""
pass
如何访问文档字符串?
我有以下功能:
def my_func():
"""My docstring is both funny and informative"""
pass
如何访问文档字符串?
在ipython或jupyter笔记本上,你可以使用上面提到的所有方法,但我同意
my_func?
or
?my_func
方法签名和文档字符串的快速摘要。
我避免使用
my_func??
(正如@rohan所评论的那样)用于docstring,并且仅用于检查源代码
import ast
import sys
f = open(sys.argv[1], "r") #filename input
module = ast.parse(f.read())
class_definitions = [node for node in module.body if isinstance(node, ast.ClassDef)]
method_definitions = []
for class_def in class_definitions:
print(class_def.name)
print(ast.get_docstring(class_def))
function_definitions = [node for node in class_def.body if isinstance(node, ast.FunctionDef)]
for f in function_definitions:
print('\t---')
print('\t'+f.name)
print('\t---')
print('\t'+'\t'.join(ast.get_docstring(f).splitlines(True)))
print('----')