How to paste examples into IPython?

2019-06-02 16:02发布

问题:

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.

回答1:

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.



回答2:

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



标签: ipython