Sriram
Sriram

Reputation: 1190

How to get interactive input from user and to be able to use arrowkeys while entering input?

When I do a raw_input() and enter values, I am not able to use my arrow-keys to change stuff... is there any way for doing that?

Thanx readline module helps in line editing features. How to use the readline module? Just importing the readline module works!

Upvotes: 8

Views: 21613

Answers (3)

user3139585
user3139585

Reputation: 31

For those looking for examples, there's a nice introduction to the readline module here: https://pymotw.com/2/readline/

Upvotes: 2

Andre85
Andre85

Reputation: 469

Try loading the readline module (import readline). That will make things work for you.

Upvotes: 11

Paul McMillan
Paul McMillan

Reputation: 20147

That's not how raw_input() works. It reads a line from the prompt, and then processes it after the newline character.

The docs are pretty clear: http://docs.python.org/library/functions.html#raw_input

If you try to throw arrow keys into the mix, your terminal is likely to add those characters to the returned string. Then again, it may not, depending on your operating system. Don't count on it.

Perhaps you want the readline module?

http://docs.python.org/library/readline.html#module-readline

Upvotes: 3

Related Questions