Skip to content

Commit

Permalink
add bytes formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
idanpa committed Jan 26, 2025
1 parent d857491 commit 1793f9c
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions calcpy/formatters.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ def str_formatter(s, printer, cycle):
s = repr(s)
printer.text(s)

def bytes_formatter(bs, printer, cycle):
printer.text(str(bs) + ' = ' + ','.join(f'0x{b:02x}' for b in bs))

def integer_to_unicode_power(integer):
s = ''
neg = ''
Expand Down Expand Up @@ -297,6 +300,7 @@ def init(ip: IPython.InteractiveShell):

formatter = ip.display_formatter.formatters['text/plain']
formatter.for_type(str, str_formatter)
formatter.for_type(bytes, bytes_formatter)
formatter.for_type(int, int_formatter)
formatter.for_type(sympy.Integer, int_formatter)
formatter.for_type(complex, complex_formatter)
Expand Down

0 comments on commit 1793f9c

Please sign in to comment.