用于复制和/或pickle输入/输出行或变量的IPython扩展。
IPythonClipboard的Python项目详细描述
关于
IPythonClipboard有两个行魔术函数,%pickle和%clip。 这两个功能都消除了使用鼠标从IPython终端复制文本的繁琐和烦人的任务。在
%picklepickle变量并将其复制到剪贴板,还可以取消剪贴板中的数据拾取。在
%clip将单元格或行的内容复制到剪贴板。在
安装
IPythonClipboard扩展是一个标准的Python包,可以使用pip安装:
pip install IPythonClipboard
安装扩展后,您可以通过执行以下操作在IPython shell中使用它:
^{pr2}$如果您发现自己经常使用这个扩展,那么您可以将它放在IPython配置文件中,以便在您打开IPython时随时可以使用它。在
转到~/.ipython/profile_default/ipython_config.py,然后将ipython_clipboard添加到:
c.TerminalIPythonApp.extensions = [ 'ipython_clipboard' ]
如果profile_default不存在,您可以通过在终端中运行ipython profile create来创建它。在
使用
%夹子
%clip用于复制输入或输出行/单元格的内容,如下所示:
In [1]: 'Hello World! ' * 2 Out[1]: 'Hello World! Hello World! ' In [2]: %clip # This will copy the output of the previous line In [2]: %clip 1 # This will copy the output of line 1 In [2]: %clip _1 # This will copy the output of line 1 In [2]: %clip _i1 # this will copy the input of line 1
也可以使用IPython缓存变量(即_ __ ___ _i _ii _iii)
%clip的docstring是:
%clip [line_number] Copies an input or output line to the clipboard. `_i7` copies the input from line 7 `_7` copies the output from line 7 `7` copies the output from line 7 positional arguments: line_number The line number to copy the contents from
%泡菜
%pickle用于将变量pickle到剪贴板中,或将剪贴板的内容解压为变量或将其打印到屏幕上。在
In [1]: my_list = [42, ('a', 'b'), 'XY', {'key': 'value'}, 3.14, True] In [2]: my_list Out[2]: [42, ('a', 'b'), 'XY', {'key': 'value'}, 3.14, True] In [3]: %pickle my_list # This will pickle `my_list` and store it in your clipboard In [3]: %pickle _2 # This will pickle the output of line 2 and store it in your clipboard (it will still be a list) In [3]: %pickle _ # This will copy the most recent output
您也可以使用IPython缓存变量(即_ __ ___ _i _ii _iii),但是,使用输入行不会对变量或表达式输出进行pickle,而是存储一个字符串。在
%pickle的docstring是:
%pickle [--output OUTPUT] [var] Pickles a variable and copies it to the clipboard or un-pickles clipboard contents and prints or stores it. `%pickle` unpickle clipboard and print `%pickle v` pickle variable `v` and store in clipboard `%pickle _` pickle last line's output and store in clipboard `%pickle -o my_var` unpickle clipboard contents and store in `my_var` positional arguments: var The variable to pickle. optional arguments: --output OUTPUT, -o OUTPUT The variable to store the output to.
发展与贡献
欢迎拉取请求:) 对于重大变化,请先打开一个问题,讨论您希望更改的内容。在
许可证
谢谢
Greg Toombs查看并帮助我改进IPythonClipboard的行号功能
- 项目
标签: