0

How can I allow the arrows in raw_input()?

There is a better way?

When I write and I use the left arrow, ^[[D appears.

I am using Linux.

luckydonald
  • 5,976
  • 4
  • 38
  • 58
Luigi001
  • 11
  • 3
  • 5
    Using arrow keys as input in Python is described [here](http://stackoverflow.com/questions/22397289/finding-the-values-of-the-arrow-keys-in-python-why-are-they-triples). – Ari Cooper-Davis Apr 09 '16 at 17:30
  • @MattDMo I don't really think this a duplicate. The linked question asks about _why_ there are 3 special letters printed. The question here is, _how_ to make the arrow keys move the cursor as expected. – luckydonald Aug 03 '18 at 16:49

2 Answers2

3

If you are Windows, the cursor keys work normally to allow editing of your input. On Linux, I find that I need to import readline to get the input editing module.

If you Google for "python readline" you will get many more hits and suggestions on enhanced editing, tab completion, etc.

PaulMcG
  • 62,419
  • 16
  • 94
  • 130
  • Just importing readline and doing nothing else fixes the arrow keys. I find this to be a little bit of witchcraft – michael Feb 11 '20 at 17:48
0

Have you tried?

myinput = raw_input("Enter your input ->")

I am using windows , it works fine. Don't have a linux to simulate.

Also, why are you pressing arrow keys? Is it a need for program?
You can simply make arrow using a dash and greater than keys.

Anil_M
  • 10,893
  • 6
  • 47
  • 74
  • 1
    I don't think the OP is trying to enter an arrow, I think they are trying to use the cursor arrows to move left and right in the input to edit the input before pressing return. – PaulMcG Apr 09 '16 at 17:45
  • In that case I think OP may be having terminal settings issue if he is trying to go left or right within `input` window. `stty sane` , followed by `export TERM=linux` may resolve the issue and also need to add `linux` tag to this question. – Anil_M Apr 09 '16 at 17:51