Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 原始输入识别^?但不是^H_Python_Linux_Raw Input - Fatal编程技术网

Python 原始输入识别^?但不是^H

Python 原始输入识别^?但不是^H,python,linux,raw-input,Python,Linux,Raw Input,我试图让backspace键在我拥有的python脚本中工作。基本上,脚本中的代码如下所示: print("Please type the character 'h':") choice = raw_input() if choice == 'h': print("Thanks.") else: print("You input the wrong character.") 现在,很明显,这是一个玩具脚本,但我很难得到raw\u input()来做我想做的事情。

我试图让backspace键在我拥有的python脚本中工作。基本上,脚本中的代码如下所示:

print("Please type the character 'h':")
choice = raw_input()
if choice == 'h':
        print("Thanks.")
else:
        print("You input the wrong character.")
现在,很明显,这是一个玩具脚本,但我很难得到
raw\u input()
来做我想做的事情。例如,如果我运行脚本,键入
a
,然后意识到我键入了错误的字符,因此点击backspace,我得到:

Please type the character 'h':
a^H
但是,如果我键入
^?
,它将转换为正确的命令:

Please type the character 'h':
<<< CURSOR HERE
请键入字符“h”:

你在用什么终端程序?它可能有一个设置,您可以使用该设置控制如何解释退格键

在gnome终端中,如果单击
Edit>Profile Preferences>Compatibility
, 当按下退格键时,您可以告诉gnome终端发送
ASCII DEL
,而不是Ctrl-h。


否则,我认为您可以使用以下方法修复您的密钥映射

xmodmap -e "keycode 22 = BackSpace"

然而,我的记忆已经生锈了。有关详细信息,请参阅和/或。

嗯,我使用的是Gnome终端,因此此建议解决了我的问题。我只是想知道为什么python会在终端中以一种方式解释它,在解释器中以另一种方式解释它。顺便说一句,谢谢你的图片。在gnome终端选项中很容易找到pref。我很感谢你抽出时间来截图,这节省了我的时间!