Python空闲帮助传呼机

时间:2018-10-04 14:38:06

标签: python python-idle

在Python Idle Shell中,help()命令的输出未分页。有什么办法可以做到这一点?

作为一种解决方法,我尝试使用pydoc.pager(),但没有成功。以下内容在从终端启动的普通Python shell中起作用,但在Python Idle 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中获取帮助文本。分页仅在终端外壳中有效。

1 个答案:

答案 0 :(得分:0)

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

为解决此问题,IDLE具有一项新功能,从3.6.7和3.7.1开始(候选版本现已上市,最终版本将在一周左右的时间内发布)。空闲将“长”输出压缩到一个按钮。 (默认情况下,“长”为50行,但用户可以修改。短的输出可以通过右键单击来压缩。)

<html>
  <head>
    <meta charset=”UTF-8">
    <meta name=”viewport” content=”width=device-width, initial-scale=1">
    <script src="https://code.jquery.com/jquery-3.3.1.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"></script>
    <!-- Katex latex renderer-->
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.10.0-rc.1/dist/katex.min.css" integrity="sha384-D+9gmBxUQogRLqvARvNLmA9hS2x//eK1FhVb9PiU86gmcrBrJAQT8okdJ4LMp2uv" crossorigin="anonymous">
    <!-- The loading of KaTeX is deferred to speed up page rendering -->
    <script defer src="https://cdn.jsdelivr.net/npm/katex@0.10.0-rc.1/dist/katex.min.js" integrity="sha384-483A6DwYfKeDa0Q52fJmxFXkcPCFfnXMoXblOkJ4JcA8zATN6Tm78UNL72AKk+0O" crossorigin="anonymous"></script>

    <!-- To automatically render math in text elements, include the auto-render extension: -->
    <script defer src="https://cdn.jsdelivr.net/npm/katex@0.10.0-rc.1/dist/contrib/auto-render.min.js" integrity="sha384-yACMu8JWxKzSp/C1YV86pzGiQ/l1YUfE8oPuahJQxzehAjEt2GiQuy/BIvl9KyeF" crossorigin="anonymous" onload="renderMathInElement(document.body);"></script>

    <!-- Bootstrap -->
    <link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">

    <!-- Bootstrap JavaScript -->
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>

    <!-- Bootstrap JavaScript -->
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.bundle.min.js" integrity="sha384-pjaaA8dDz/5BgdFUPX6M/9SUZv4d12SUPF0axWc+VRZkx5xU3daN+lYb49+Ax+Tl" crossorigin="anonymous"></script>

    

    <!-- Slate Bootswatch theme -->
    <link href="https://stackpath.bootstrapcdn.com/bootswatch/4.1.3/slate/bootstrap.min.css" rel="stylesheet" integrity="sha384-ywjdn7N8uoxzIfGl7jlEBlqw2BNicOSzZDgo7A2ffvbM24Ct9plRp7KwtaIqZ33j" crossorigin="anonymous">

    <title>title</title> 
  </head>
  <body>
  <nav class="navbar navbar-expand-lg navbar-dark bg-primary">
    <div class="container">
        <a class="navbar-brand" href="#">Navbar</a>
        <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
          <span class="navbar-toggler-icon"></span>
        </button>
      <div class="collapse navbar-collapse" id="navbarNav">
        <ul class="navbar-nav mr-auto">
          <li class="nav-item">
            <a class="nav-link" href="/index.ejs">Home</a>
          </li>
          <li class="dropdown">
            <a class="dropdown-toggle" data-toggle="dropdown" href="#">Notes
            <span class="caret"></span></a>
            <ul class="dropdown-menu">
              <li><a href="#">Lambda Calculus</a></li>
              <li><a href="#">Languages and Machines</a></li>
              <li><a href="#">Logic Programming</a></li>
              <li><a href="#">Types and Programming languages</a></li>
            </ul>
          </li>
          <li class="nav-item">
            <a class="nav-link" href="/posts.ejs">Posts</a>
          </li>
          <li class="nav-item">
            <a class="nav-link" href="/about.ejs">About</a>
          </li>
        </ul>
      </div>
    </div>
  </nav>
  <div class="container">
    <div class="row bg-light">
      <div class="col-md-auto text-dark">
        <div id="notes">
         <p>PAGE CONTENT</p>
        </div>  
      </div>
    </div>
  </div>
<footer class="footer">
    <div class="container">
      <span class="text-muted">&copy; Me. All external content belongs to their respective owners.</span>
    </div>
  </footer>
  </body>
</html>

您可以双击扩展文本,或者右键单击扩展到剪贴板或单独的非模式视图窗口。一个单独的窗口允许您在命令行管理程序中编写语句时在帮助条目中上下滚动或翻页。