您可以使用NumpyDocString from
numpydoc将文档字符串解析为Python友好的结构。
这是一个如何使用它的示例:
from numpydoc.docscrape import NumpyDocStringclass Photo(): """ Array with associated photographic information. Parameters ---------- x : type Description of parameter `x`. y Description of parameter `y` (with type not specified) Attributes ---------- exposure : float Exposure in seconds. Methods ------- colorspace(c='rgb') Represent the photo in the given colorspace. gamma(n=1.0) Change the photo's gamma exposure. """ def __init__(x, y): print("Snap!")doc = NumpyDocString(Photo.__doc__)print(doc["Summary"])print(doc["Parameters"])print(doc["Attributes"])print(doc["Methods"])
但是,由于我不了解的原因,这不适用于您给出的示例(也没有很多我想在其上运行的代码)。相反,您需要根据用例使用特定的
FunctionDoc或
ClassDoc类。
from numpydoc.docscrape import FunctionDocdef foobar(a, b): """ Something something Parameters ---------- a : int, default: 5 Does something cool b : str Wow """doc = FunctionDoc(foobar)print(doc["Parameters"])
我通过在他们的源代码中查看此测试来弄清所有内容。因此,这并没有真正记录在案,但是希望足以让您入门。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)