Python交互模式历史记录和箭头键 [英] Python interactive mode history and arrow keys

查看:115
本文介绍了Python交互模式历史记录和箭头键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有人可以解释为什么在Python交互模式下突然所有箭头键都失败了?

I was wondering if anyone can explain why all of a sudden in Python interactive mode all arrow keys are failing?

例如,当我按下向上按钮浏览命令历史记录时,我得到"^ [[A]".与其他任何箭头键相同.

When I press up button for example to go through command history I get "^[[A". Same with any other arrow keys.

我不知道为什么会发生这种情况,并且以前没有发生过(在OS X Snow Leopard上).有人知道解决此问题的方法吗?

I have no idea why this happened and it was working before (on OS X Snow Leopard). Does anyone know a way to fix this?

非常感谢,

G

推荐答案

您没有说您使用的是哪个Python,但您提到的症状确实通常是由于Python没有使用readline支持而构建的.如今,可以将OS X上的Python构建为使用GNU readline库或Apple提供的editline库(又名AKA libedit).您可以使用以下两个命令来确切显示所使用的Python.如果那不能帮助您确定发生了什么,请编辑问题以显示这些命令的输出.

You don't say which Python you are using but the symptoms you mention are indeed usually caused by Python not being built with readline support. These days Python on OS X can be built to use either the GNU readline library or the Apple-supplied editline library (AKA libedit). You can use the following two commands to show exactly which Python you are using. If that does not help you figure out what is going on, edit your question to show the output from those commands.

下面是显示OS X 10.6上最新的MacPorts Python 2.6的示例:

Here's an example that shows a recent MacPorts Python 2.6 on OS X 10.6:

$ python -c 'import sys;print(sys.version);print(sys.executable)'
2.6.5 (r265:79063, Jul 15 2010, 01:53:46) 
[GCC 4.2.1 (Apple Inc. build 5659)]
/opt/local/Library/Frameworks/Python.framework/Versions/2.6/Resources/Python.app/Contents/MacOS/Python

$ otool -L $(python -c 'import readline; print(readline.__file__)')
/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-dynload/readline.so:
    /opt/local/lib/libreadline.6.1.dylib (compatibility version 6.0.0, current version 6.1.0)
    /opt/local/lib/libncursesw.5.dylib (compatibility version 5.0.0, current version 5.0.0)
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 125.2.0)

路径前缀/opt/local/是MacPorts安装的软件的默认位置,并且otool的输出表明此Python的readline模块已动态链接到MacPorts安装的GNU readline库.

The path prefix /opt/local/ is the default location for MacPorts-installed software and the output from otool indicates that this Python's readline module is dynamically linked to the MacPorts-installed GNU readline library.

这篇关于Python交互模式历史记录和箭头键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆