Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ipython: %paste over ssh connection

Tags:

ipython

In ipython >=0.11, the %paste command is required to paste indented commands. However, if I run an ipython shell in a remote terminal, the buffer %paste refers to is on the remote machine rather than the local machine. Is there any way around this?

like image 772
keflavich Avatar asked Nov 12 '11 20:11

keflavich


2 Answers

I think this is exactly what %cpaste is for (I am always forgetting about all the things IPython does). %cpaste enters a state allowing you to paste already formatted or indented code, and it will strip leading indentation and prompts, so you can copy/paste indented code from files, or even from an interactive Python session including leading >>> or In [1] which will be stripped.

like image 142
minrk Avatar answered Nov 12 '22 13:11

minrk


Not a brilliant solution, but I think this will work:

Use %autoindent to turn off autoindenting, type if True: and press enter. Then paste your indented code.

I think it should be possible to write an IPython extension to handle this better. I'll try to get round to looking into it. I've made an issue.

If you use IPython a lot, you may want to get the new kernel/client architecture working - it should be possible to tunnel the connections over SSH, so you can use the Qt console on your local machine, talking to a kernel on a server. But that might take a bit of fiddling to get in place.

like image 39
Thomas K Avatar answered Nov 12 '22 13:11

Thomas K