Skip to main content
 首页 » 编程设计

python之在 Python 2.7 交互模式下使用 .help() 函数后无法退出提示

2024年10月01日7虾米姐

我刚开始学习 Python,并在交互模式下对不同的 String 方法使用 help() 函数。 例如:

>>> S = 'abcd' 
>>> help(S.isdigit) 

输出符合预期:

Help on built-in function isdigit: 
 
isdigit(...) 
    S.isdigit() -> bool 
 
    Return True if all characters in S are digits 
    and there is at least one character in S, False otherwise. 
(END) 

不幸的是,无论我按什么按钮,我似乎都无法退出此提示(CTRL+D 也不起作用)。 我可以关闭终端,但这显然很麻烦。

我使用的是 Ubuntu 16.04 LTS。

提前感谢您的任何建议!

请您参考如下方法:

在 Python 的交互式 shell 中输入 help 调用 pydoc .

When printing output to the console, pydoc attempts to paginate the output for easier reading. If the PAGER environment variable is set, pydoc will use its value as a pagination program.

除非您以其他方式配置它,否则 pydoc 可能使用 less .在这种情况下,按 Q 退出。


注意:许多程序使用 less 之类的键绑定(bind)。我会将 Q 添加到您的键盘命令列表中,以便在您不知道如何退出程序时尝试。