Skip to content

Instantly share code, notes, and snippets.

@JonathonReinhart
Created February 18, 2017 18:17
Show Gist options
  • Save JonathonReinhart/a63823a2c5bd097bd5666868104de98e to your computer and use it in GitHub Desktop.
Save JonathonReinhart/a63823a2c5bd097bd5666868104de98e to your computer and use it in GitHub Desktop.
Default hex output in Python interactive console
# 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