Baffled by readline module

Cameron Simpson cs at cskk.id.au
Fri Mar 10 15:51:17 EST 2023


On 10Mar2023 09:12, Grant Edwards <grant.b.edwards at gmail.com> wrote:
>On 2023-03-10, Weatherby,Gerard <gweatherby at uchc.edu> wrote:
>> On our Linux systems, I can up-arrow to go back to prior commands
>> and use the left and right arrows to navigate a line. The
>> functionality may be provided internally by readline. I’ve never had
>> to dig into it because it meets my needs out of the box.
>
>Apparently the cmd.Cmd docs are wrong. It says:
>
>      If the readline module is loaded, input will automatically
>      inherit bash-like history-list editing (e.g. Control-P scrolls
>      back to the last command, Control-N forward to the next one,
>      Control-F moves the cursor to the right non-destructively,
>      Control-B moves the cursor to the left non-destructively, etc.).
>
>On my Python 3.10.10 Linux system, cmd.Com itself is importing the
>readline module unconditionally when I call cmdloop(). There's no 'if'
>about it.

I was wondering about that myself, whether this is an accident of 
phrasing. It doesn't say "is imported", so maybe the author was thinking 
"if readline's part of the install" here.

Anyway, I've got a try/import-readline/except-importerror/pass in my 
cmd.Cmd wrapper, because I read this the way you read it.

Cheers,
Cameron Simpson <cs at cskk.id.au>


More information about the Python-list mailing list