内容表

  • 14. 交互输入编辑和历史代入
    • 14.1. Tab 补全和历史编辑
    • 14.2. 替代交互解释器

上一话题

13. 现在怎么办?

下一话题
就业培训     下载中心     Wiki     联络
登录   注册

Log
  1. 首页
  2. Python 3.12.4
  3. 索引
  4. 模块
  5. 下一
  6. 上一
  7. Python 教程
  8. 14. 交互输入编辑和历史代入

14. 交互输入编辑和历史代入 ¶

某些版本的 Python 解释器支持编辑当前输入行和历史代入,类似在 Korn Shell 和 GNU Bash Shell 中找到的设施。此实现使用 GNU Readline 库,支持各种样式的编辑。此库拥有自己的文档编制 (在此不再赘述)。

14.1. Tab Completion and History Editing ¶

变量和模块名称的补全是 automatically enabled at interpreter startup so that the Tab key invokes the completion function; it looks at Python statement names, the current local variables, and the available module names. For dotted expressions such as string.a , it will evaluate the expression up to the final '.' and then suggest completions from the attributes of the resulting object. Note that this may execute application-defined code if an object with a __getattr__() method is part of the expression. The default configuration also saves your history into a file named .python_history in your user directory. The history will be available again during the next interactive interpreter session.

14.2. Alternatives to the Interactive Interpreter ¶

This facility is an enormous step forward compared to earlier versions of the interpreter; however, some wishes are left: It would be nice if the proper indentation were suggested on continuation lines (the parser knows if an indent token is required next). The completion mechanism might use the interpreter’s symbol table. A command to check (or even suggest) matching parentheses, quotes, etc., would also be useful.

One alternative enhanced interactive interpreter that has been around for quite some time is IPython , which features tab completion, object exploration and advanced history management. It can also be thoroughly customized and embedded into other applications. Another similar enhanced interactive environment is bpython .

内容表

  • 14. 交互输入编辑和历史代入
    • 14.1. Tab 补全和历史编辑
    • 14.2. 替代交互解释器

上一话题

13. 现在怎么办?

下一话题

15. 浮点算术:问题和局限性

本页

  • 报告 Bug
  • 展示源

快速搜索

键入搜索术语或模块、类、函数名称。

  1. 首页
  2. Python 3.12.4
  3. 索引
  4. 模块
  5. 下一
  6. 上一
  7. Python 教程
  8. 14. 交互输入编辑和历史代入

版权所有  © 2014-2026 乐数软件    

工业和信息化部: 粤ICP备14079481号-1