Baffled by readline module
Grant Edwards
grant.b.edwards at gmail.com
Thu Mar 9 16:08:46 EST 2023
On 2023-03-09, Chris Angelico <rosuav at gmail.com> wrote:
> Not sure about the history file, and I would assume that if you don't
> configure one, history is simply lost when you restart. But with tab
> completion, unless you need to be able to input a tab character, it
> should be safe to ignore the feature and leave it at the defaults.
Indeed, that seems to be how it works (though I never found that
stated anywhere in the docs).
What's really weird about the docs is that when it is described it
doesn't even _mention_ that it provides command-line recall and
editing:
The readline module defines a number of functions to facilitate
completion and reading/writing of history files from the Python
interpreter. This module can be used directly, or via the
rlcompleter module, which supports completion of Python
identifiers at the interactive prompt. Settings made using this
module affect the behaviour of both the interpreter’s interactive
prompt and the prompts offered by the built-in input() function.
It just talks about manipulating history files and about
tab-completion of Python identfiers. The last sentence mentions that
settings affect both the REPL prompt and the prompts offered by the
built-in input() function.
However, I also don't really care about the "prompts offered"
either. What I care about is the interactive handling of user
keystrokes vis-a-vis command line recall and editing.
Or is that what's meant by the phrase "behavior of the prompt"?
To me "the prompt" is the string that's printed _before_ the program
starts reading user keystrokes and doing the stuff I care about.
It finally dawned on me after seeing an example I found elsewhere that
you don't call some module method to fetch the next user-entered line.
You call the input() built-in.
Having a module modify the behavior of a built-in makes me cringe.
I suppose this way you can easily slap-on "readline" command-line
recall/editing to an existing application as long as it uses the
input() built-in instead of reading from stdin.
--
Grant
More information about the Python-list
mailing list