blob: abf30f020dea0060e6fa5a4a7d31ae36e3351732 [file] [log] [blame]
Georg Brandl116aa622007-08-15 14:28:22 +00001.. _tut-interacting:
2
3**************************************************
4Interactive Input Editing and History Substitution
5**************************************************
6
7Some versions of the Python interpreter support editing of the current input
8line and history substitution, similar to facilities found in the Korn shell and
Georg Brandlc5605df2009-08-13 08:26:44 +00009the GNU Bash shell. This is implemented using the `GNU Readline`_ library,
Antoine Pitrou1a6cb302013-05-04 20:08:35 +020010which supports various styles of editing. This library has its own
11documentation which we won't duplicate here.
Georg Brandl116aa622007-08-15 14:28:22 +000012
13
14.. _tut-keybindings:
15
Antoine Pitrou1a6cb302013-05-04 20:08:35 +020016Tab Completion and History Editing
17==================================
Georg Brandl116aa622007-08-15 14:28:22 +000018
Antoine Pitrou1a6cb302013-05-04 20:08:35 +020019Completion of variable and module names is
20:ref:`automatically enabled <rlcompleter-config>` at interpreter startup so
21that the :kbd:`Tab` key invokes the completion function; it looks at
22Python statement names, the current local variables, and the available
23module names. For dotted expressions such as ``string.a``, it will evaluate
24the expression up to the final ``'.'`` and then suggest completions from
25the attributes of the resulting object. Note that this may execute
26application-defined code if an object with a :meth:`__getattr__` method
27is part of the expression. The default configuration also saves your
28history into a file named :file:`.python_history` in your user directory.
29The history will be available again during the next interactive interpreter
30session.
Georg Brandl116aa622007-08-15 14:28:22 +000031
32
33.. _tut-commentary:
34
Georg Brandlc5605df2009-08-13 08:26:44 +000035Alternatives to the Interactive Interpreter
36===========================================
Georg Brandl116aa622007-08-15 14:28:22 +000037
38This facility is an enormous step forward compared to earlier versions of the
39interpreter; however, some wishes are left: It would be nice if the proper
40indentation were suggested on continuation lines (the parser knows if an indent
41token is required next). The completion mechanism might use the interpreter's
42symbol table. A command to check (or even suggest) matching parentheses,
43quotes, etc., would also be useful.
44
Georg Brandlc5605df2009-08-13 08:26:44 +000045One alternative enhanced interactive interpreter that has been around for quite
Éric Araujode4f05b2011-08-06 01:51:07 +020046some time is IPython_, which features tab completion, object exploration and
Georg Brandlc5605df2009-08-13 08:26:44 +000047advanced history management. It can also be thoroughly customized and embedded
48into other applications. Another similar enhanced interactive environment is
Éric Araujode4f05b2011-08-06 01:51:07 +020049bpython_.
Georg Brandlc5605df2009-08-13 08:26:44 +000050
Georg Brandl116aa622007-08-15 14:28:22 +000051
Georg Brandlc5605df2009-08-13 08:26:44 +000052.. _GNU Readline: http://tiswww.case.edu/php/chet/readline/rltop.html
53.. _IPython: http://ipython.scipy.org/
54.. _bpython: http://www.bpython-interpreter.org/