如何从IDLE访问命令历史记录?

问题:如何从IDLE访问命令历史记录?

在bash或Window的命令提示符上,我们可以按键盘上的向上箭头以获取最后一个命令,然后对其进行编辑,然后再次按Enter以查看结果。

但是在Python的IDLE 2.6.5或3.1.2中,似乎如果我们的语句打印出了25行,我们需要按向上箭头25次到最后一个命令,然后按Enter才能将其复制?

还是使用鼠标查明该行并单击那里,然后按Enter键进行复制?有没有更快的方法?

On bash or Window’s Command Prompt, we can press the up arrow on keyboard to get the last command, and edit it, and press ENTER again to see the result.

But in Python’s IDLE 2.6.5 or 3.1.2, it seems if our statement prints out 25 lines, we need to press the up arrow 25 times to that last command, and press ENTER for it to be copied?

Or use the mouse to pinpoint that line and click there, and press ENTER to copy? Is there a faster way?


回答 0

  • 我认为您正在寻找history-previous action,默认情况下绑定到Alt+ P
  • 您可以在“ 选项->配置IDLE->密钥 ”中重新映射它
  • 您还可以从IDLE的顶部菜单访问此命令:“ Shell-> Previous History

顺便说一句,为什么不尝试像bpythonipython这样的更好的外壳(对于初学者来说更难看)?

  • I think you are looking for the history-previous action, which is bound to Alt+P by default.
  • You can remap it in “Options -> Configure IDLE -> Keys
  • You can also access this command from the top menu in IDLE: “Shell -> Previous History

Incidentally, why don’t you try a better (less ugly, for starters) shell like bpython or ipython?


回答 1

只是Alt+P用来上去。同样,Alt+N可以用来下降。

just use Alt+P to go up. Similarly, Alt+N could be used to go down.


回答 2

如果您使用的是Mac,则为ctrl+ p

If you’re on mac, it’s ctrl+p.


回答 3

进入“首选项”>“键”。在列表中找到“历史上一个”选项,并将其编辑为“向上箭头”。

Go into Preferences > Keys. Find the ‘history-previous’ selection in the list and edit it to Up Arrow.


回答 4

默认情况下,您始终可以编辑〜/ .idlerc下的config-keys.cfg文件。查找条目“ history-previous”,并将其设置为如下所示…

history-previous = <Key-Up>

做完了

You can always edit the file config-keys.cfg found under ~/.idlerc by default; look for the entry “history-previous” and set it to as below…

history-previous = <Key-Up>

Done.