如何将示例粘贴到IPython中? [英] How to paste examples into IPython?

查看:84
本文介绍了如何将示例粘贴到IPython中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

网上已经有了python代码示例,这些示例来自vanila Python shell

The web is full with python code examples that are either taken from vanila Python shell

>>> for i in range(10):
...  print(i)
... 

....或来自IPython shell:

.... or from IPython shell:

In [1]: for i in range(10):
   ...:     print(i)
   ...:     print(i + 1)
   ...:     

当我想将这些片段粘贴到IPython中时,我需要将它们粘贴到文本编辑器中,进行一些查找和替换,然后将其粘贴到IPython中。我确信有更好的方法,但找不到它。

When I want to paste such snippets into IPython, I need to paste them into a text editor, do some find-and-replace and then paste it into IPython. I'm sure there is a better way, but can't find it.

推荐答案

%paste 命令有效,但我实际上看的是什么for是%doctest_mode 。可以在这里找到更酷的黑客

The %paste command works, but what I was actually looking for was %doctest_mode. More cool hacks can be found here

这篇关于如何将示例粘贴到IPython中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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