Issue
I want to insert my ipython terminal session in to a text file. The usual way of ipython >> test.txt
does not work and collect too much garbage.
Preferably I am looking for some thing that does not require the use of this test.txt
or some intermediary file.
I have seen quite a number of Ipython's code snippets. How do they do it? More specifically I am writing some handouts in latex
using vim
and would need frequent insertion of of such sessions. Through vim
I also tried :r!ipython
, but it does not work and too much garbage.
Solution
You can save specific lines from the current session into a file with save <filename> <range>
:
save line 13 into
filename.py
In [26]: save filename 13
save lines 1 to 25 into
filename.py
In [26]: save filename 1-25
save lines 6 to 10 and 18 to 25 into
filename.py
In [27]: save filename 6-10 18-25
You can also use %edit
to open the specified lines in a text editor:
In [55]: edit 23-32
Answered By - romainl
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.