Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Python pprint with color syntax highlighting for the console
from pygments import highlight
from pygments.lexers import PythonLexer
from pygments.formatters import Terminal256Formatter
from pprint import pformat
def pprint_color(obj):
print highlight(pformat(obj), PythonLexer(), Terminal256Formatter())
@RyanFleck

This comment has been minimized.

Copy link

@RyanFleck RyanFleck commented Oct 3, 2018

Thanks a bunch! Works well in Jupyter notebooks. (Extra parentheses needed for Python 3.)

@idobarnoam

This comment has been minimized.

Copy link

@idobarnoam idobarnoam commented Apr 15, 2019

Thanks for this!

@laike9m

This comment has been minimized.

Copy link

@laike9m laike9m commented Apr 11, 2020

Thanks!

@laknath

This comment has been minimized.

Copy link

@laknath laknath commented Jun 14, 2020

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment