14. Інтерактивне редагування введення та заміна історії¶
Деякі версії інтерпретатора Python підтримують редагування поточного рядка введення та заміну історії, подібно до можливостей оболонки Korn і оболонки GNU Bash. Це реалізовано за допомогою бібліотеки GNU Readline, яка підтримує різні стилі редагування. Ця бібліотека має власну документацію, яку ми не будемо тут дублювати.
14.1. Доповнення вкладок і редагування історії¶
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. Альтернативи інтерактивному інтерпретатору¶
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.
Одним з альтернативних розширених інтерактивних інтерпретаторів, який існує вже досить давно, є IPython, який включає завершення вкладок, дослідження об’єктів і розширене керування історією. Його також можна ретельно налаштувати та вбудувати в інші програми. Ще одне подібне розширене інтерактивне середовище — bpython.