Skip to content

Instantly share code, notes, and snippets.

@rwarren
Created March 7, 2014 20:54
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 rwarren/9419899 to your computer and use it in GitHub Desktop.
Save rwarren/9419899 to your computer and use it in GitHub Desktop.
python displayhook for pprint by default
#lifted from http://stackoverflow.com/questions/17248383/pretty-print-by-default-in-python-repl
import pprint
import sys
orig_displayhook = sys.displayhook
def myhook(value):
if value != None:
__builtins__._ = value
pprint.pprint(value)
__builtins__.pprint_on = lambda: setattr(sys, 'displayhook', myhook)
__builtins__.pprint_off = lambda: setattr(sys, 'displayhook', orig_displayhook)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment