kak*_*eys 122 python shell interpreter virtualenv python-idle
如何重复上一个命令?通常的键:Up,Ctrl + Up,Alt-p不起作用.他们产生荒谬的人物.
(ve)[kakarukeys@localhost ve]$ python
Python 2.6.6 (r266:84292, Nov 15 2010, 21:48:32)
[GCC 4.4.4 20100630 (Red Hat 4.4.4-10)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> print "hello world"
hello world
>>> ^[[A
File "<stdin>", line 1
^
SyntaxError: invalid syntax
>>> ^[[1;5A
File "<stdin>", line 1
[1;5A
^
SyntaxError: invalid syntax
>>> ^[p
File "<stdin>", line 1
p
^
SyntaxError: invalid syntax
>>>
Run Code Online (Sandbox Code Playgroud)
小智 157
在IDLE中,转到选项 - >配置IDLE - >键,然后选择history-next,然后选择history-previous来更改键.
然后单击"获取选择新键",您就可以选择所需的任何组合键.
pyf*_*unc 54
我使用以下命令在python shell上启用历史记录.
这是我的.pythonstartup文件.PYTHONSTARTUP环境变量设置为此文件路径.
# python startup file
import readline
import rlcompleter
import atexit
import os
# tab completion
readline.parse_and_bind('tab: complete')
# history file
histfile = os.path.join(os.environ['HOME'], '.pythonhistory')
try:
readline.read_history_file(histfile)
except IOError:
pass
atexit.register(readline.write_history_file, histfile)
del os, histfile, readline, rlcompleter
Run Code Online (Sandbox Code Playgroud)
您将需要使用readline,rlcompleter模块来启用此功能.
请查看以下信息:http://docs.python.org/using/cmdline.html#envvar-PYTHONSTARTUP.
所需模块:
小智 46
Alt + p用于来自histroy的前一个命令,Alt + n用于历史记录中的下一个命令.
这是默认配置,您可以从选项 - >配置IDLE更改这些键快捷键.
Inf*_*5ek 16
你没有具体说明哪个翻译.假设你正在使用IDLE.
来自IDLE文档:命令历史:
Alt-p retrieves previous command matching what you have typed.
Alt-n retrieves next.
(These are Control-p, Control-n on the Mac)
Return while cursor is on a previous command retrieves that command.
Expand word is also useful to reduce typing.
Run Code Online (Sandbox Code Playgroud)
在Ubuntu Server 12.04上,从源代码(Python3.4)安装Python版本后,我遇到了这个问题.
这里的一些评论建议安装Ipython,我想提一下,即使使用Ipython,我也有同样的行为.据我所知,这是一个readline问题.
为Ubuntu 12.04服务器,我必须安装libncurses-dev并libreadline-dev再启用从源代码安装Python达历史(readline的)行为.我差不多这样做了:
sudo apt-get install libncurses-dev libreadline-dev
Run Code Online (Sandbox Code Playgroud)
之后,我删除了以前安装的Python(不是系统PYTHON,我从源代码安装的那个!)并从源代码重新安装它,一切都按预期工作.
我没有用pip安装任何东西或编辑.pythonstartup.
小智 7
默认情况下,使用ALT + p作为上一个命令,你可以改为Up-Arrow而不是IDLE GUi >> OPtions >>配置IDLE >> Key >> Custom Key Binding除了readlines模块之外,运行自定义脚本不是必需的在Windows中运行.希望有所帮助.:)