开发者

Python get __doc__ documentation for instance variable

开发者 https://www.devze.com 2023-03-01 00:48 出处:网络
In python, I know I\'m supposed to document instance variables like this: self.x = 22 \"\"\"docstring for x\"\"\"

In python, I know I'm supposed to document instance variables like this:

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

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

But I can't seem to find a way to get hold of that documentation 开发者_高级运维in code. MyClass.x.__doc__ gives me the doc of the actual type that is in x

So the question is: How do I get "docstring for x" from self.x?


This is a feature of documentation utilities such as Sphinx and Epydoc, not a standard feature of Python. I don't believe that there is any direct way of getting variable docstrings.

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


According to PEP 257, instance variables are supposed to be documented in the docstring of the class:

The docstring for a class should summarize its behavior and list the public methods and instance variables.

Just writing the docstring after the initialisation of an instance variable won't give you any way to access it.

0

精彩评论

暂无评论...
验证码 换一张
取 消