Python Tip

Every Python book and website tutorial recommends the following command for prompting the user for input:

raw_input()

But I have found that this command is buggy and unreliable.

Specifically, I wrote a long, complex code that had several raw_input() commands.

The code ran successfully in Spyder. But I received the following error when I ran it in console mode: “Readline internal error” plus some other cryptic messages about console.py, hook_wrapper_23 & NoneType.

The error occurred when the code executed the second raw_input().

After hours of struggle, I found that I could use the following command instead:

sys.stdin.readline()

sys.stdin.readline() works in both Sypder and external command-line mode.

sys.stdin.readline() is a superior alternative.

Yes, my perceptions are colored by my inexperience, but I like commands that reliably work straight out-of-the-box.  So I will stick with sys.stdin.readline().

Leave a Comment