How to stop the input function from inserting a new line?

But how do I stop raw_input from writing a newline?

In short: You can’t.

raw_input() will always echo the text entered by the user, including the trailing newline. That means whatever the user is typing will be printed to standard output.

If you want to prevent this, you will have to use a terminal control library such as the curses module. This is not portable, though — for example, curses in not available on Windows systems.

Leave a Comment