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?
-
how is the input received? Via terminal or another program?smac89– smac892013-08-15 17:36:36 +00:00Commented Aug 15, 2013 at 17:36
Add a comment
|
2 Answers
If you import the readline module, raw_input() should use it with no further modification, and you'll get better control sequence support.
Comments
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'