How do I access the command history from IDLE?

2020-05-11 11:05发布

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?

5条回答
beautiful°
2楼-- · 2020-05-11 11:37

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.

查看更多
ら.Afraid
3楼-- · 2020-05-11 11:38
  • 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?

查看更多
我命由我不由天
4楼-- · 2020-05-11 11:39

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

查看更多
5楼-- · 2020-05-11 11:43

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

Idle settings

查看更多
时光不老,我们不散
6楼-- · 2020-05-11 11:45

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

查看更多
登录 后发表回答