trouble with cmd.Cmd and prompting

Cameron Simpson cs at
Wed Jan 18 05:49:31 EST 2017

On 04Jan2017 12:20, Cameron Simpson <cs at> wrote:
>I will try to get a minimal example others can run.

Well I've made some time for this, and it seems to be an interaction with my 
python3, the "input" builtin, and readline. Cmd.cmdloop behaves fine if I turn 
off the .raw_input attribute, and I can reproduce the issue without the cmd 

Test code:

  import readline
  line = input("F> ")
  line = input("G> ")

Results on a terminal:

  [~]fleet*2> python3
  F> a
  F> gap
  G> %                                                                                    

That "%" is an artifact of no final newline after the "G> ".

If I comment out the import of readline it looks like this:

  G> %                                                                                    
  [~]fleet*> python3
  F> a
  G> b

as one would expect. Ignoring my shell prompts, the contents of a typescript 

  F> a^M
  F> gap^M

Those "^M"s are carriage returns. I kind of suspect the second "F> " is 
readline doing some kind of redraw. I am baffled by the lack of initial "G> " 
prompt; that "G> " above appears to be the secondary issue, after I've pressed 
return for the "b" line.

This is on a Mac, so I've no strace command to hand. I've also got all manner 
of potential special stuff (readline library from MacPorts, etc). I'll keep 
stripping stuff back...

Cameron Simpson <cs at>

More information about the Python-list mailing list