Skip to content

Instantly share code, notes, and snippets.

Created Aug 9, 2018
What would you like to do?
use hex instead of ascii when display bytes in ipython
to load allhex any where
copy and to folder "~/.local/lib/python3.7/site-packages/allhex/"
(3.7 is your python version)
from .allhex import *
use "%load_ext allhex" to load it
use "%unload_ext allhex" to unload it
to load it automatically, add
`get_ipython().run_line_magic('load_ext', 'allhex')`
to your ~/.ipython/profile_default/startup/
def load_ipython_extension(ipython):
formatter = ipython.display_formatter.formatters['text/plain']
def _repr(obj, p, cycle):
s = "b'" + (''.join(f'\\x{c:02x}' for c in obj)) + "'"
formatter.for_type(bytes, _repr)
def unload_ipython_extension(ipython):
formatter = ipython.display_formatter.formatters['text/plain']
formatter.for_type(bytes, lambda obj, p, cycle: p.text(str(obj)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment