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