Created
February 18, 2017 18:17
-
-
Save JonathonReinhart/a63823a2c5bd097bd5666868104de98e to your computer and use it in GitHub Desktop.
Default hex output in Python interactive console
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
# Display integers as hex and decimal | |
import sys | |
def displayhook(item): | |
if isinstance(item, int) and not isinstance(item, bool): | |
print '0x{0:X} ({0})'.format(item) | |
elif isinstance(item, long): | |
print '0x{0:X}L ({0}L)'.format(item) | |
elif item is not None: | |
print repr(item) | |
sys.displayhook = displayhook | |
del sys, displayhook |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment