FiesoDuck
FiesoDuck

Reputation: 79

How to navigate the text cursor in pythons input() prompt with arrow keys

I want to reposition the text cursor in an python input() prompt

msg = input()
print(msg)

When the user presses the left or right arrow key, the text cursor should be repositioned left or right respectively. This is to allow the user to edit the previously entered text.

Instead the arrow key values are printed ^[[D, ^[[C etc.

Upvotes: 6

Views: 1158

Answers (1)

Jules
Jules

Reputation: 445

Do this (importing readline will allow you to use the arrows) :

import readline

msg = input()
print(msg)

Upvotes: 9

Related Questions