public
Created

IPython startup script which configures IPython to log all input/output and does so *without cluttering the prompt* when starting IPython

  • Download Gist
ipython_startup_script.py
Python
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
from time import strftime
import os.path
import contextlib
import cStringIO
import sys
 
 
# create a context which we can use for any block which we can use for any
# block which we do not want to print stdout
# -- taken from http://stackoverflow.com/a/2829036/217652
 
@contextlib.contextmanager
def nostdout():
save_stdout = sys.stdout
sys.stdout = cStringIO.StringIO()
yield
sys.stdout = save_stdout
 
 
 
ip = get_ipython()
 
ldir = ip.profile_dir.log_dir
fname = strftime('%Y-%m-%d-%H-%M-%S') + ".py"
filename = os.path.join(ldir, fname)
 
 
# stdout is now muted
with nostdout():
ip.run_line_magic('logstart', '-o %s append' % filename)

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.