I want to capture the output of the following ipython command into a file: commands and outputs areas follows:
`decoder.get_hyp()`
WARNING: "ngram_search.c", line 1000: </s> not found in last frame, using ++NOISE++ instead
INFO: ngram_search.c(1046): lattice start node <s>.0 end node ++NOISE++.171
INFO: ps_lattice.c(1225): Normalizer P(O) = alpha(++NOISE++:171:185) = -2003082
INFO: ps_lattice.c(1263): Joint P(O,S) = -2036704 P(S|O) = -33622
Out[7]: ('WELCOME TO MY TALK', '000000000', -36704586)
I want to capture only the part "wellcome to my talk" into my file.
Just do as follow:
PS: Some additional useful command:
'_' refers to the previous output.
Or you can:
'i' refers to the output history number, you can see output first via:
Use the IPython magic function
store
The
%%capture
cell magic saves the stdout/stderr output of running a command, if that's what you need. Here's the usage syntax:And, here's a usage example:
The output object is an instance of
IPython.utils.capture.CapturedIO
, which has a neat interface for accessing stdout/stderr or combined output.IPython captures the value (output) of the last command in the variable _ (underscore).
will open the value of a variable in your editor.
So, "%edit _", should enable you to edit and save the value of the last command.
See the History section of the IPython docs
And to learn about the possible arguments to the %edit magic function, type the following at the ipython prompt: