代码之家  ›  专栏  ›  技术社区  ›  Karl Marklund

Python空闲帮助寻呼机

  •  0
  • Karl Marklund  · 技术社区  · 6 年前

    在Python空闲shell中 help() 命令未分页。有没有办法做到这一点?

    pydoc.pager()

    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和空闲shell中的帮助文本。分页只能在终端外壳中工作。

    1 回复  |  直到 6 年前
        1
  •  1
  •   Terry Jan Reedy    6 年前

    为了解决这个问题,IDLE提供了一个新特性,从3.6.7和3.7.1开始(候选版本现在已经提供,最终版本将在一周左右发布)。空闲挤压'长'输出到一个按钮(默认情况下,“long”是50行,但用户可以修改它。右击可压缩短路输出。)

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

    可以通过双击就地展开文本,也可以通过右键单击将文本展开到剪贴板或单独的非模式视图窗口中。在Shell中编写语句时,可以通过一个单独的窗口在帮助条目中上下滚动或翻页。