开发者

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!


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


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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜