14. Editarea interactivă a datelor de intrare și substituții în istoric¶
Anumite versiuni ale interpretorului de Python ne permit editarea comenzilor introduse (în linia de comandă), respectiv reluarea execuției unora din itemii listei de comenzi a istoricului (sesiunii de lucru și nu numai; calitate denumită, generic, substituții în istoric, de la englezescul history substitution), aidoma celor puse la dispoziția utilizatorului de către facilitățile disponibile în interpretoarele de comenzi Korn și GNU Bash. Mecanismele software sunt implementate pe baza bibliotecii GNU Readline, în care utilizatorul își poate alege stilul de editare (din setul celor acceptate). Această bibliotecă are documentație proprie (bogată), pe care nu o vom reproduce aici.
14.1. Completări din tabulator și editarea istoricului¶
Completion of variable and module names is
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. Alternative la interpretorul interactiv¶
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.
O alternativă (la interpretorul de Python actual) este cea oferită de un interpretor interactiv avansat, disponibil de destul de mult timp, care se numește IPython, interpretor capabil de completări din tabulator, de explorare a obiectelor și de o administrare sofisticată a istoricului. În plus, el poate fi personalizat în privința punctelor-cheie, respectiv scufundat în codul altor aplicații. Asemănător lui este și mediul interactiv extins intitulat bpython.