Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
IPython startup script which configures IPython to log all input/output and does so *without cluttering the prompt* when starting IPython
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
def nostdout():
save_stdout = sys.stdout
sys.stdout = cStringIO.StringIO()
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment