-
-
Save shaybensasson/7cf69de164f3911c6d4a84530d0cc177 to your computer and use it in GitHub Desktop.
Python pprint with color syntax highlighting for the console (adapted for python3.6)
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 pygments import highlight | |
from pygments.formatters.terminal256 import Terminal256Formatter | |
from pygments.lexers.python import PythonLexer | |
def pprint_color(obj): | |
print(highlight(pformat(obj), PythonLexer(), Terminal256Formatter())) | |
import pygments | |
print(pygments.__version__) #2.6.1 | |
if __name__ == '__main__': | |
l = [{'beta': 0.0003, | |
'exception': None, | |
'pid': 23309, | |
'result': 0.1477420465869912}, | |
{'beta': 3.0, 'exception': None, 'pid': 23309, 'result': 0.8701576752649646}, | |
{'beta': 0.0005, | |
'exception': None, | |
'pid': 23310, | |
'result': 0.1477420465869912}, | |
{'beta': 1.0, | |
'exception': Exception('You huuu', ), | |
'pid': 23310, | |
'result': None}, | |
{'beta': 0.001, 'exception': None, 'pid': 23310, 'result': 0.8701576752649646}, | |
{'beta': 0.5, 'exception': None, 'pid': 23310, 'result': 0.31501170037258275}, | |
{'beta': 0.003, | |
'exception': None, | |
'pid': 23309, | |
'result': 0.31501170037258275}, | |
{'beta': 0.3, 'exception': None, 'pid': 23309, 'result': 0.6795055168423021}, | |
{'beta': 0.005, 'exception': None, 'pid': 23310, 'result': 0.6795055168423021}, | |
{'beta': 0.1, 'exception': None, 'pid': 23310, 'result': 0.5446195499457295}, | |
{'beta': 0.01, 'exception': None, 'pid': 23309, 'result': 0.5446195499457295}, | |
{'beta': 0.05, 'exception': None, 'pid': 23309, 'result': 0.37445485098821485}, | |
{'beta': 0.03, 'exception': None, 'pid': 23310, 'result': 0.37445485098821485}] | |
pprint_color(l) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment