1

This is a pretty basic question I'm having trouble with. I have a python program, and when I use raw_input to get user input, whenever I try to delete something the user already types, this symbol appears: ^H, instead of allowing me to delete what I have already typed. How can I allow users to delete previous things they've typed?

1
  • how is the input received? Via terminal or another program? Commented Aug 15, 2013 at 17:36

2 Answers 2

5

If you import the readline module, raw_input() should use it with no further modification, and you'll get better control sequence support.

More info: http://docs.python.org/2/library/readline.html

Sign up to request clarification or add additional context in comments.

Comments

1

In you case you will want to play with the cmd module. Like this:

import cmd
import sys, string
class CLI(cmd.Cmd):
    def __init__(self):
        cmd.Cmd.__init__(self)
        self.prompt = '> '
        self.text=''
    def do_input(self, arg):
        self.text=arg
        sys.exit(1)

Try it out:

">>> cli=CLI()

">>> cli.cmdloop()

"> input test

">>> cli.text

'test'

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.