在Python交互式shell中,是否可以将上一个命令复制到剪贴板?

2024-04-25 21:55:48 发布

您现在位置:Python中文网/ 问答频道 /正文

交互式shell中是否有将最后一个表达式复制到剪贴板的命令?你知道吗

我知道有_命令,它重复最后一个表达式的求值,例如

>>>  " ".join(['a', 'b', 'c'])
'a b c'
>>> _
'a b c'

但我要找的是一个将" ".join(['a', 'b', 'c'])复制到剪贴板的命令。有这样的事吗?你知道吗


Tags: 命令表达式shelljoin剪贴板
2条回答

您可以使用终端仿真器的工具来实现这一点。你知道吗

在Python本身中,没有这样的功能,但是可以为IPythonhere's one for Linux and MacOS添加一个用户提供的魔术命令。你知道吗

使用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'

相关问题 更多 >