Last active
October 10, 2024 04:42
-
-
Save EdwardBetts/0814484fdf7bbf808f6f to your computer and use it in GitHub Desktop.
Python pprint with color syntax highlighting for the 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
from pprint import pformat | |
from typing import Any | |
from pygments import highlight | |
from pygments.formatters import Terminal256Formatter | |
from pygments.lexers import PythonLexer | |
def pprint_color(obj: Any) -> None: | |
"""Pretty-print in color.""" | |
print(highlight(pformat(obj), PythonLexer(), Terminal256Formatter()), end="") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I've updated the gist for Python 3 and added type hints.