If you import the readline
module, raw_input()
should use it with no further modification, and you'll get better control sequence support.
Allowing users to delete user input in python
Domanda
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?
Soluzione
Altri suggerimenti
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'
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow