擅长:python、mysql、java
<p><code>help</code>函数(在<code>pydoc</code>模块中实现)没有准备好查找每个实例的docstring。我快速浏览了一下这个模块,看看是否有一种方法可以提供明确的帮助,但似乎没有。它使用<code>inspect</code>模块来确定它是什么类型的东西,而myFunc看起来不像函数,而是一个实例。所以pydoc打印实例类的帮助。在</p>
<p>如果与<code>__doc__</code>类似,可以添加一个<code>__help__</code>属性,但不支持该属性。在</p>
<p>我不太愿意建议,但您最好还是定义一个新的<code>help</code>函数:</p>
<pre><code>old_help = help
def help(thing):
if hasattr(thing, '__help__'):
print thing.__help__
else:
old_help(thing)
</code></pre>
<p>然后在实例上添加<code>__help__</code>属性:</p>
^{pr2}$