Created
July 24, 2013 08:36
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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