在Python中调用help(help)时,“扭曲”是什么意思?

时间:2016-12-25 15:56:50

标签: python python-2.x pydoc

def digit(n): n = str(n) # the rest of the code 这是pydoc.help的一个包装(有一个扭曲)。

有什么变化?

help(help)

1 个答案:

答案 0 :(得分:6)

没有太大的变化。扭曲是pydoc lazily 导入,对象有一个__repr__方法,提供有关如何使用对象的直接反馈:

>>> repr(help)
'Type help() for interactive help, or help(object) for help about object.'

只要您在交互式提示中回显__repr__对象,就会调用help方法:

>>> help
Type help() for interactive help, or help(object) for help about object.

Python 3.4完全摆脱了'扭曲'的描述,取而代之的是一些更具描述性的东西;见issue 9364。引用臭虫记者:

  

“(扭曲)”非常感谢。我认为应该删除或解释评论。参考手册应该解释,而不是挑逗。

然后是开发人员的回复:

  

同意。我认为“扭曲”是导入是懒惰的,并且帮助有一个有用的repr(哇,谈论扭曲!)。这些细节不需要提及,只需删除评论(“包装”是IMO足以提高好奇心,来源就是在这里找到包装的内容)。

docstring现在写着:

class _Helper(object):
    """Define the builtin 'help'.

    This is a wrapper around pydoc.help that provides a helpful message
    when 'help' is typed at the Python interactive prompt.

    Calling help() at the Python prompt starts an interactive help session.
    Calling help(thing) prints help for the python object 'thing'.
    """