pprintpp: a drop-in replacement for pprint that’s actually pretty
That description should explain all what pprintpp (GitHub) does. It’s like the original pprint only with extra pp in its tail in terms of usage:
>>> import pprintpp >>> pprintpp.pprint(...)
You can use it as a command-line tool as well, though it has never occured to me to use pprint() via CLI:
$ echo "{'hello': 'world'}" | pypprint {'hello': 'world'}
You can also monkey patch the original pprint with pprintpp.monkeypatch() without touching any existing pprint.pprint() calls to have prettier output.
A simple example:
>>> foobar = {'a': 123, ... 'b': [7, ... {'blah': 'lol'}, ... (1, 3, 4), ... np.array([[1,2],[3,4]])], ... 'c': 'abc'} >>> pprint.pprint(foobar) {'a': 123, 'b': [7, {'blah': 'lol'}, (1, 3, 4), array([[1, 2], [3, 4]])], 'c': 'abc'} >>> pprintpp.pprint(foobar) { 'a': 123, 'b': [ 7, {'blah': 'lol'}, (1, 3, 4), array([[1, 2], [3, 4]]), ], 'c': 'abc', }
It makes sure each item gets its own line and align well with its siblings.
pprintpp is written by David Wolever under the Simplified BSD License (2-clause), currently version 0.1.1 (2014-03-30).
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.