Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

^H ^? in python

Some terminals will send ^? as backspace, some other terminals will send ^H. Most of the terminals can be configured to change their behavior. I do not want to deal with all the possible combinations but I would like to accept both ^? and ^H as a backspace from python.

doing this

os.system("stty erase '^?'")

I will accept the first option and with

os.system("stty erase '^H'")

I will accept the second one but the first will be no longer available. I would like to use

raw_input("userinput>>")

to grab the input.

The only way I was able to figure out is implementing my own shell which works not on "raw based input" but on "char based input".

Any better (and quicker) idea?

like image 728
Jekyll Avatar asked Jan 23 '12 18:01

Jekyll


1 Answers

The built-in function raw_input() (or input() in Python 3) will automatically use the readline library after importing it. This gives you a nice and full-feautured line editor, and it is probably your best bet on platforms where it is available, as long as you don't mind Readline having a contagious licence (GPL).

like image 154
Sven Marnach Avatar answered Sep 21 '22 07:09

Sven Marnach