Package: pprintpp
Now with Python 3 support!Installationpprint++can be installed with Python 2 or Python 3 usingpiporeasy_install:$ pip install pprintpp
- OR -
$ easy_install pprintppUsagepprint++can be used in three ways:Through the separatepppackage:$ pip install pp-ez
$ python
...
>>> import pp
>>> pp(["Hello", "world"])
["Hello", "world"]For more, seehttps://pypi.python.org/pypi/pp-ezAs a command-line program, which will read Python literals from standard in
and pretty-print them:$ echo "{'hello': 'world'}" | pypprint
{'hello': 'world'}As anipythonextension:In [1]: %load_ext pprintppThis will use pprintpp for ipython’s output.To load this extension when ipython starts, put the previous line in yourstartup file.You can change the indentation level like so:In [2]: %config PPrintPP.indentation = 4To monkeypatchpprint:>>> import pprintpp
>>> pprintpp.monkeypatch()
>>> import pprint
>>> pprint.pprint(...)Note: the originalpprintmodule will be available withimport pprint_original. Additionally, a warning will be issued ifpprinthas
already been imported. This can be suppressed by passingquiet=True.And, if youreallywant, it can even be imported as a regular module:>>> import pprintpp
>>> pprintpp.pprint(...)Usability ProtipsppFor bonus code aesthetics,pprintpp.pprintcan be imported aspp:>>>frompprintppimportpprintaspp>>>pp(...)And if that is just too many letters, thepp-ezpackage can be installed
from PyPI, ensuring that pretty-printing is never more than animport ppaway:$ pip install pp-ez
$ python
...
>>> import pp
>>> pp(["Hello", "world"])
["Hello", "world"]For more, seehttps://pypi.python.org/pypi/pp-ezWhy is it prettier?Unlikepprint,pprint++strives to emit a readable, largely
PEP8-compliant, representation of its input.It also has explicit support for: thecollectionsmodule (defaultdictandCounter) andnumpyarrays:>>>importnumpyasnp>>>fromcollectionsimportdefaultdict,Counter>>>pprint([np.array([[1,2],[3,4]]),defaultdict(int,{"foo":1}),Counter("aaabbc")])[
    array([[1, 2],
           [3, 4]]),
    defaultdict(<type 'int'>, {'foo': 1}),
    Counter({'a': 3, 'b': 2, 'c': 1}),
]Unicode characters, when possible, will be printed un-escaped. This is done by
checking both the output stream’s encoding (defaulting toutf-8) and the
character’s Unicode category. An effort is made to print only characters which
will be visually unambiguous: letters and numbers will be printed un-escaped,
spaces, combining characters, and control characters will be escaped:>>>unistr=u"\xe9e\u0301">>>printunistréé>>>pprint(unistr)u'ée\u0301'The output stream’s encoding will be considered too:>>>importio>>>stream=io.BytesIO()>>>stream.encoding="ascii">>>pprint(unistr,stream=stream)>>>printstream.getvalue()u'\xe9e\u0301'Subclassess of built-in collection types which don’t define a new__repr__will have their class name explicitly added to their repr. For example:>>>classMyList(list):...pass...>>>pprint(MyList())MyList()>>>pprint(MyList([1,2,3]))MyList([1, 2, 3])Note that, as you might expect, custom__repr__methods will be respected:>>>classMyList(list):...def__repr__(self):...return"custom repr!"...>>>pprint(MyList())custom repr!Note:pprint++is still under development, so the formatwillchange
and improve over time.ExampleWithprintpp:>>>importpprintpp>>>pprintpp.pprint(["Hello",np.array([[1,2],[3,4]])])[
    'Hello',
    array([[1, 2],
           [3, 4]]),
]>>>pprintpp.pprint(tweet){
    'coordinates': None,
    'created_at': 'Mon Jun 27 19:32:19 +0000 2011',
    'entities': {
        'hashtags': [],
        'urls': [
            {
                'display_url': 'tumblr.com/xnr37hf0yz',
                'expanded_url': 'http://tumblr.com/xnr37hf0yz',
                'indices': [107, 126],
                'url': 'http://t.co/cCIWIwg',
            },
        ],
        'user_mentions': [],
    },
    'place': None,
    'source': '<a href="http://www.tumblr.com/" rel="nofollow">Tumblr</a>',
    'truncated': False,
    'user': {
        'contributors_enabled': True,
        'default_profile': False,
        'entities': {'hashtags': [], 'urls': [], 'user_mentions': []},
        'favourites_count': 20,
        'id_str': '6253282',
        'profile_link_color': '0094C2',
    },
}Withoutprintpp:>>> import pprint
>>> import numpy as np
>>> pprint.pprint(["Hello", np.array([[1,2],[3,4]])])
['Hello', array([[1, 2],
       [3, 4]])]
>>> tweet = {'coordinates': None, 'created_at': 'Mon Jun 27 19:32:19 +0000 2011', 'entities': {'hashtags': [], 'urls': [{'display_url': 'tumblr.com/xnr37hf0yz', 'expanded_url': 'http://tumblr.com/xnr37hf0yz', 'indices': [107, 126], 'url': 'http://t.co/cCIWIwg'}], 'user_mentions': []}, 'place': None, 'source': '<a href="http://www.tumblr.com/" rel="nofollow">Tumblr</a>', 'truncated': False, 'user': {'contributors_enabled': True, 'default_profile': False, 'entities': {'hashtags': [], 'urls': [], 'user_mentions': []}, 'favourites_count': 20, 'id_str': '6253282', 'profile_link_color': '0094C2'}}
>>> pprint.pprint(tweet)
{'coordinates': None,
 'created_at': 'Mon Jun 27 19:32:19 +0000 2011',
 'entities': {'hashtags': [],
              'urls': [{'display_url': 'tumblr.com/xnr37hf0yz',
                        'expanded_url': 'http://tumblr.com/xnr37hf0yz',
                        'indices': [107, 126],
                        'url': 'http://t.co/cCIWIwg'}],
              'user_mentions': []},
 'place': None,
 'source': '<a href="http://www.tumblr.com/" rel="nofollow">Tumblr</a>',
 'truncated': False,
 'user': {'contributors_enabled': True,
          'default_profile': False,
          'entities': {'hashtags': [], 'urls': [], 'user_mentions': []},
          'favourites_count': 20,
          'id_str': '6253282',
          'profile_link_color': '0094C2'}}