[英]When in Python interactive shell, can I copy the previous command to the clipboard?
Is there a command in the interactive shell that copies the last expression to the clipboard?交互式 shell 中是否有将最后一个表达式复制到剪贴板的命令?
I know there's the _
command, which repeats the last expression's evaluation, eg我知道有_
命令,它重复最后一个表达式的评估,例如
>>> " ".join(['a', 'b', 'c'])
'a b c'
>>> _
'a b c'
But what I'm looking for is a command that copies " ".join(['a', 'b', 'c'])
to the clipboard.但我正在寻找的是一个将" ".join(['a', 'b', 'c'])
复制到剪贴板的命令。 Is there such a thing?有这样的事情吗?
You can do that with your terminal emulator's tools.您可以使用终端模拟器的工具来做到这一点。
In Python itself, there's no such functionality -- but one can add a user-supplied magic command for IPython -- here's one for Linux and MacOS .在 Python 本身中,没有这样的功能——但可以为 IPython 添加一个用户提供的魔法命令——这里有一个适用于 Linux 和 MacOS 的功能。
Use ipython terminal..使用 ipython 终端..
$ ipython
Python 3.6.6 |Anaconda, Inc.| (default, Jun 28 2018, 11:07:29)
Type 'copyright', 'credits' or 'license' for more information
IPython 6.5.0 -- An enhanced Interactive Python. Type '?' for help.
In [1]: " ".join(['a', 'b', 'c'])
Out[1]: 'a b c'
In [2]: _
Out[2]: 'a b c'
In [3]: _1
Out[3]: 'a b c'
In [4]: __
Out[4]: 'a b c'
In [5]: _
Out[5]: 'a b c'
In [6]: _1
Out[6]: 'a b c'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.