Python 空闲帮助寻呼机

Python Idle help pager

从 Python 空闲 shell,help() 命令的输出未分页。有什么办法可以实现吗?

作为解决方法,我尝试使用 pydoc.pager() 但没有成功。以下工作正常 Python shell 从终端启动但不是 Python 空闲 shell。

import pydoc

def ihelp(thing):
    '''Render text documentation, given an object or a path to an object, and
    sends the resulting text to a pager.'''

    pydoc.pager(pydoc.render_doc(thing))

编辑: 为了避免误会。 ihelp() 函数在终端 Python shell 和 IDLE shell 中获取帮助文本。分页仅适用于终端 shell.

您的代码可以提供帮助输出,但不能分页。寻呼机在用户代码 运行 进程中执行,并且不知道如何在单独的 gui 进程中与 IDLE shell 交互。我不相信你能改变这个。

为了解决这个问题,IDLE 从 3.6.7 和 3.7.1 开始有一个新功能(候选版本现已可用,最终版本将在一周左右发布)。 IDLE 压缩 'long' 输出到一个按钮。 (默认'long'为50行,用户可自行修改。短输出可通过右击压缩。)

>>> help(int)
[ Squeezed text (241 lines) ]  # <== tkinter button
>>> 

您可以通过双击就地展开文本,或者通过右键单击将文本展开到剪贴板或单独的非模式视图 window。单独的 window 允许在 Shell.

中编写语句时在帮助条目中上下滚动或翻页