Is there a way to redirect stderr to file in Jupyter?
Question: There was a redirect_output function in IPython.utils, and there was a
%%capture magic function, but these are now gone, and [this
thread](http://stackoverflow.com/questions/14571090/ipython-redirecting-
output-of-a-python-script-to-a-file-like-bash) on the topic is now outdated.

I'd like to do something like the following:

    
    
    from IPython.utils import io
    from __future__ import print_function
    with io.redirect_output(stdout=False, stderr="stderr_test.txt"):
        while True:
            print('hello!', file=sys.stderr)
    

Thoughts? For more context, I am trying to capture the output of some ML
functions that run for hours or days, and output a line every 5-10 seconds to
stderr. I then want to take the output, munge it, and plot the data.


Answer: You could probably try replacing `sys.stderr` with some other file descriptor
the same way as suggested [here](http://stackoverflow.com/a/31153046/232371).

    
    
    import sys
    oldstderr = sys.stderr
    sys.stderr = open('log.txt', 'w')
    # do something
    sys.stderr = oldstderr
    

