Search code examples
pythonraw-inputbackspace

Backspace with `raw_input` in Python


I am using raw_input() like this:

while True:
  print "MC ID (CTRL-D = done, 0 = sets, ? = lookup):",
  try:
    mcid=raw_input()
  except:
    print
    break
  # evaluate user input
  # ...

Now if you type something, e.g. abc and hit backspace to correct something, as soon as you remove the a, the output from print is erased as well (and the cursor jumps to the beginning of the line), so that you no longer see the input prompt. Is there a way to avoid this?


Solution

  • Try this:

    mcid = raw_input("MC ID (CTRL-D = done, 0 = sets, ? = lookup): ")