How to paste examples into IPython?

空扰寡人 提交于 2019-12-10 11:34:38

问题


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



来源:https://stackoverflow.com/questions/24242707/how-to-paste-examples-into-ipython

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!