如何在pycharm中反转控制台历史顺序以进行复制粘贴? [英] How to invert console history order in pycharm for copy pasting?

查看:242
本文介绍了如何在pycharm中反转控制台历史顺序以进行复制粘贴?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Pycharm中,控制台历史记录包含从最新(顶部)到最旧(底部)的条目。这在某种程度上是好的,但是从历史中复制粘贴几行代码是很可怕的。
当从历史记录中复制时,会使您的代码流程颠倒过来。基本上,你必须一次复制+粘贴一行,代价是打开历史记录并每次滚动到所需的行。

In Pycharm, the console history has entries from newest (top) to oldest (bottom). Which is fine in a way, but it's horrible for copy pasting several lines of code from history. What happens is that you get your code flow upside down when copying from history. Basically, you have to copy+paste one line at a time, at the cost of opening the history and scrolling to the desired line every single time.

它不是重要的是,如果您按照您希望重新输入的顺序选择您的行。控制台历史记录弹出窗口将根据显示的顺序对它们进行排序(即,最新的顶部,最旧的底部)。

It doesn't matter if you Ctrl select your lines in the order you want them to be re-entered. The console history pop-up will sort them according to the order shown (i.e., newest on top, oldest in the bottom).

示例:
说你在控制台上运行以下两行

Example: Say you ran the following two lines on console

import pandas as pd
df = pd.read_csv('path_to_file')

当您查看历史记录时,您会看到以下内容:

When you look it up on history, this is what you'll see:

1 df = pd.read_csv('path_to_file')
2 import pandas as pd

因此,如果您选择这两行将其粘贴到控制台或脚本中,它们将以错误的顺序排列,从而打破代码流。

So, if you select those two lines to paste it in the console or in your script, they'll be in the incorrect order, breaking down code flow.

我搜索了一种方法:
(1)反转控制台历史记录的显示方式(即最旧(最高)到最新(底部)) 。
(2)保留选择顺序(即忽略历史记录,按Ctrl +单击顺序,这样在上面的示例中我可以先选择第2行,第1行第2行,这个顺序将被保留用于粘贴)。

I have searched for a way to either: (1) invert how console history is displayed (i.e., oldest (top) to newest (bottom)). (2) preserve selecting order (i.e, ignore position on history, order by Ctrl+click, so that in the example above I could select line #2 first, line #1 second and this order would be preserved for pasting).

应用程序:

a)重新运行先前在控制台中输入的代码片;

a) Rerun previously entered code slices in console;

b)从控制台历史记录复制到脚本文件。

b) copy from console history to script file.

提前致谢。干杯!

推荐答案

另一个选择是,如果您安装了 ipython ,那么你的python控制台默认使用 ipython 。您可以使用 ipython %history magic命令打印出您的历史记录以供复制。

Another option is that if you have ipython installed, then your python console will by default use ipython. And you could use the %history magic command of ipython to print out your history for copy.

cf http://ipython.readthedocs.io/en/stable/ interactive / magics.html#magic-history

这篇关于如何在pycharm中反转控制台历史顺序以进行复制粘贴?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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