17db96d56Sopenharmony_ci.. _tut-interacting: 27db96d56Sopenharmony_ci 37db96d56Sopenharmony_ci************************************************** 47db96d56Sopenharmony_ciInteractive Input Editing and History Substitution 57db96d56Sopenharmony_ci************************************************** 67db96d56Sopenharmony_ci 77db96d56Sopenharmony_ciSome versions of the Python interpreter support editing of the current input 87db96d56Sopenharmony_ciline and history substitution, similar to facilities found in the Korn shell and 97db96d56Sopenharmony_cithe GNU Bash shell. This is implemented using the `GNU Readline`_ library, 107db96d56Sopenharmony_ciwhich supports various styles of editing. This library has its own 117db96d56Sopenharmony_cidocumentation which we won't duplicate here. 127db96d56Sopenharmony_ci 137db96d56Sopenharmony_ci 147db96d56Sopenharmony_ci.. _tut-keybindings: 157db96d56Sopenharmony_ci 167db96d56Sopenharmony_ciTab Completion and History Editing 177db96d56Sopenharmony_ci================================== 187db96d56Sopenharmony_ci 197db96d56Sopenharmony_ciCompletion of variable and module names is 207db96d56Sopenharmony_ci:ref:`automatically enabled <rlcompleter-config>` at interpreter startup so 217db96d56Sopenharmony_cithat the :kbd:`Tab` key invokes the completion function; it looks at 227db96d56Sopenharmony_ciPython statement names, the current local variables, and the available 237db96d56Sopenharmony_cimodule names. For dotted expressions such as ``string.a``, it will evaluate 247db96d56Sopenharmony_cithe expression up to the final ``'.'`` and then suggest completions from 257db96d56Sopenharmony_cithe attributes of the resulting object. Note that this may execute 267db96d56Sopenharmony_ciapplication-defined code if an object with a :meth:`__getattr__` method 277db96d56Sopenharmony_ciis part of the expression. The default configuration also saves your 287db96d56Sopenharmony_cihistory into a file named :file:`.python_history` in your user directory. 297db96d56Sopenharmony_ciThe history will be available again during the next interactive interpreter 307db96d56Sopenharmony_cisession. 317db96d56Sopenharmony_ci 327db96d56Sopenharmony_ci 337db96d56Sopenharmony_ci.. _tut-commentary: 347db96d56Sopenharmony_ci 357db96d56Sopenharmony_ciAlternatives to the Interactive Interpreter 367db96d56Sopenharmony_ci=========================================== 377db96d56Sopenharmony_ci 387db96d56Sopenharmony_ciThis facility is an enormous step forward compared to earlier versions of the 397db96d56Sopenharmony_ciinterpreter; however, some wishes are left: It would be nice if the proper 407db96d56Sopenharmony_ciindentation were suggested on continuation lines (the parser knows if an indent 417db96d56Sopenharmony_citoken is required next). The completion mechanism might use the interpreter's 427db96d56Sopenharmony_cisymbol table. A command to check (or even suggest) matching parentheses, 437db96d56Sopenharmony_ciquotes, etc., would also be useful. 447db96d56Sopenharmony_ci 457db96d56Sopenharmony_ciOne alternative enhanced interactive interpreter that has been around for quite 467db96d56Sopenharmony_cisome time is IPython_, which features tab completion, object exploration and 477db96d56Sopenharmony_ciadvanced history management. It can also be thoroughly customized and embedded 487db96d56Sopenharmony_ciinto other applications. Another similar enhanced interactive environment is 497db96d56Sopenharmony_cibpython_. 507db96d56Sopenharmony_ci 517db96d56Sopenharmony_ci 527db96d56Sopenharmony_ci.. _GNU Readline: https://tiswww.case.edu/php/chet/readline/rltop.html 537db96d56Sopenharmony_ci.. _IPython: https://ipython.org/ 547db96d56Sopenharmony_ci.. _bpython: https://www.bpython-interpreter.org/ 55