How to paste examples into IPython?

2019-06-02 16:27发布

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

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

.... or from IPython shell:

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

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.

标签: ipython
2条回答
劫难
2楼-- · 2019-06-02 16:39

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

查看更多
【Aperson】
3楼-- · 2019-06-02 16:55

In IPython you can call %paste it will paste your clipboard in terminal.

Note: As far as I know you should install tkinter for using %paste.

查看更多
登录 后发表回答