Last active
January 19, 2017 00:25
-
-
Save chekunkov/848c3472d4b0bee69bccd2e77907a590 to your computer and use it in GitHub Desktop.
PYTHONSTARTUP file example with custom displayhook
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
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@yipeipei good point, fixed