Skip to content

Instantly share code, notes, and snippets.

@chekunkov
Last active January 19, 2017 00:25
Show Gist options
  • Save chekunkov/848c3472d4b0bee69bccd2e77907a590 to your computer and use it in GitHub Desktop.
Save chekunkov/848c3472d4b0bee69bccd2e77907a590 to your computer and use it in GitHub Desktop.
PYTHONSTARTUP file example with custom displayhook
#!/usr/bin/env python
import sys
import pprint
def displayhook_pprint(o):
"""Display hook powered by pprint.
https://www.python.org/dev/peps/pep-0217/
"""
if o is None:
return
if sys.version_info[0] == 2:
import __builtin__ as builtins
else:
import builtins
# Set '_' to None to avoid recursion
# https://docs.python.org/3/library/sys.html#sys.displayhook
builtins._ = None
pprint.pprint(o)
builtins._ = o
sys.displayhook = displayhook_pprint
@chekunkov
Copy link
Author

@yipeipei good point, fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment