Skip to content

Instantly share code, notes, and snippets.

@sente
Created July 24, 2013 08:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sente/6068935 to your computer and use it in GitHub Desktop.
Save sente/6068935 to your computer and use it in GitHub Desktop.
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 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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment