trouble with cmd.Cmd and prompting

Peter Otten __peter__ at
Wed Jan 18 07:47:47 EST 2017

Cameron Simpson wrote:

> 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 module.
> Test code:
>   import readline
>   line = input("F> ")
>   print("gap")
>   line = input("G> ")

If readline is not used input() writes its prompt to stderr. I don't have a 
Mac, but it might be worthwhile to investigate what goes where. For 
comparison here's what happens on my Linux system:

$ cat
import sys

if "-r" in sys.argv:
    import readline

    "uses readline" if "readline" in sys.modules
    else "no readline"
line = input("F> ")
line = input("G> ")

$ python3
no readline
F> alpha
G> beta

$ python3 2>/dev/null
no readline

$ python3 -r 2>/dev/null
uses readline
F> alpha
G> beta

More information about the Python-list mailing list