gpt4 book ai didi

Python 获取实例变量的 __doc__ 文档

转载 作者:行者123 更新时间:2023-11-28 19:36:04 25 4
gpt4 key购买 nike

在 python 中,我知道我应该像这样记录实例变量:

self.x = 22
"""docstring for x"""

#: docstring for x
self.x = 22
self.x = 22 #: docstring for x

但我似乎无法找到一种方法来获取代码中的文档。 MyClass.x.__doc__ 给我 x

中实际类型的文档

所以问题是:如何从 self.x 获取 "docstring for x"

最佳答案

这是 Sphinx 和 Epydoc 等文档实用程序的一项功能,而不是 Python 的标准功能。我不相信有任何直接的方法可以获取可变文档字符串。

参见 http://epydoc.sourceforge.net/manual-docstring.html#variable-docstrings

关于Python 获取实例变量的 __doc__ 文档,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5793306/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com