[IPython-user] capture run output to a file
Tue Mar 27 00:32:02 CDT 2007
On 3/26/07, John Hunter <firstname.lastname@example.org> wrote:
> Is there a easyish, somewhat elegantish way to capture the output of a
> "run somefile.py" command to a file or file handle?
Not really, I'm afraid.
I sometimes use the code attached here for this purpose. It's only a
minimally more sophisticated version of what you posted, and I use it
# Save all output to a file
trans = utils.TranscriptPrint(start=True)
[... normal code runs ...]
# At the end, remember this:
You need to remember that if for any reason the script exits before
the final .stop() call is made, you should manually do it yourself
when you're back in ipython. Otherwise you lose readline. Obviously
a try/finally or a 2.5 context manager could be used to ensure the
stop() call is always made, but I don't actually bother with it.
It would be nice to have something like this available in a more
convenient fashion, a la 'tee' at the unix command line...
-------------- next part --------------
A non-text attachment was scrubbed...
Size: 2240 bytes
Desc: not available
Url : http://lists.ipython.scipy.org/pipermail/ipython-user/attachments/20070326/1af439f5/attachment.py
More information about the IPython-user