擅长:python、mysql、java
<p>我不太清楚你的问题到底是什么。我的理解是,您在其中定义了一个类和一个函数,并且您想知道Python从哪里获得该函数的帮助文本。在</p>
<p>Python从类/方法中提供的doc字符串获取帮助文本。在</p>
<p>如果您在该类中有一个类“a”和一个方法“f”,并且函数“f”中有docstring,那么下面的终端转储应该有助于澄清您的问题:</p>
<pre><code>>>> class A:
def __init__(self):
self.c = 0 # some class variable
def f(self, x):
"""this is the documentation/help text for the function "f" """
return x+1
>>> help(A.f)
Help on method f in module __main__:
f(self, x) unbound __main__.A method
this is the documentation/help text for the function "f"
>>> A.f.__doc__
'this is the documentation/help text for the function "f" '
</code></pre>
<p>希望这有帮助</p>