Skip to main content

A drop-in replacement for pprint that's actually pretty

Project description

Installation

$ pip install pprintpp

The pprint++ source distribution also contains a package called pp, a convinient alias for pprintpp. The pp package is optional, but must be installed separately:

$ pip install pp-ez
$ python
...
>>> import pp
>>> pp(["Hello", "world"])
["Hello", "world"]

For more, see https://pypi.python.org/pypi/pp-ez

Usage

pprint++ can be used in three ways:

  1. As a regular module:

    >>> import pprintpp
    >>> pprintpp.pprint(...)
  2. As a command-line program, which will read Python literals from standard in and pretty-print them:

    $ echo "{'hello': 'world'}" | pypprint
    {'hello': 'world'}
  3. To monkeypatch pprint:

    >>> import pprintpp
    >>> pprintpp.monkeypatch()
    >>> import pprint
    >>> pprint.pprint(...)

    Note: the original pprint will be available with import pprint_original.

  4. Through the separate pp package:

    $ pip insatll pp-ez
    $ python
    ...
    >>> import pp
    >>> pp(["Hello", "world"])
    ["Hello", "world"]

    For more, see https://pypi.python.org/pypi/pp-ez

Why is it prettier?

Unlike pprint, pprint++ strives to emit a readable, largely PEP8-complient, representation of its input.

It also has explicit support for: the collections module (defaultdict and Counter) and numpy arrays.

Note: pprint++ is still under development, so the format will change and improve over time.

Example

With printpp:

>>> import pprintpp
>>> 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',
    },
}

Without printpp:

>>> 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'}}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pprintpp-0.1.2.tar.gz (6.0 kB view details)

Uploaded Source

Built Distribution

pprintpp-0.1.2-py27-none-any.whl (8.3 kB view details)

Uploaded Python 2.7

File details

Details for the file pprintpp-0.1.2.tar.gz.

File metadata

  • Download URL: pprintpp-0.1.2.tar.gz
  • Upload date:
  • Size: 6.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for pprintpp-0.1.2.tar.gz
Algorithm Hash digest
SHA256 f2d2860cd2af614177ec8f0ae6407a53fa572b2f0bf046cc3ea8afb838a277c8
MD5 3ea9ec7024f50b7bf2424e47aed0e51c
BLAKE2b-256 cd18e21c38236ebd1037a6e71f8f62f228ed177e65c5d8634141372b9b3272c1

See more details on using hashes here.

File details

Details for the file pprintpp-0.1.2-py27-none-any.whl.

File metadata

File hashes

Hashes for pprintpp-0.1.2-py27-none-any.whl
Algorithm Hash digest
SHA256 7f3c97cd3272f28c11825d90d8701d3988f021070c2b3a479eb6d2efdc1c4f15
MD5 8543033ad45cdbefb15aed26841767be
BLAKE2b-256 bb25e50ae11ea121cc379db4a16c907eb47de4bdf5d44df96ada5fad8ee56035

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page