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:
As a regular module:
>>> import pprintpp >>> pprintpp.pprint(...)
As a command-line program, which will read Python literals from standard in and pretty-print them:
$ echo "{'hello': 'world'}" | pypprint {'hello': 'world'}
To monkeypatch pprint:
>>> import pprintpp >>> pprintpp.monkeypatch() >>> import pprint >>> pprint.pprint(...)
Note: the original pprint will be available with import pprint_original.
Through the separate pp package:
$ pip install 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-compliant, representation of its input.
It also has explicit support for: the collections module (defaultdict and Counter) and numpy arrays.
Unicode characters, when possible, will be printed un-escaped. This is done by checking both the output stream’s encoding (defaulting to utf-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"
>>> print unistr
éé
>>> pprint(unistr)
u'ée\u0301'
The output stream’s encoding will be considered too:
>>> import io
>>> stream = io.BytesIO()
>>> stream.encoding = "ascii"
>>> pprint(unistr, stream=stream)
>>> print stream.getvalue()
u'\xe9e\u0301'
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file pprintpp-0.1.3.tar.gz
.
File metadata
- Download URL: pprintpp-0.1.3.tar.gz
- Upload date:
- Size: 8.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9c146e42f67a83aa7da84a15e45e88b28e5b552eb7afebee51c397cd2aca8c8a |
|
MD5 | 98dd5d69e1707e5c1e888d4f4e21bef5 |
|
BLAKE2b-256 | c7e85fd3a7cca0b4ae3d5c675e67b04fc0cec21f1f7b7b6ccecf6cc9f9bb8f9e |
File details
Details for the file pprintpp-0.1.3-py27-none-any.whl
.
File metadata
- Download URL: pprintpp-0.1.3-py27-none-any.whl
- Upload date:
- Size: 10.8 kB
- Tags: Python 2.7
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6a401c3925e7c4413dad26269b1668e7588c88a2610d95fabecaf57640eb1504 |
|
MD5 | 7720a00aeb6475f56f3d15051753c2a7 |
|
BLAKE2b-256 | e637d0ee36e400160c58493fa7144037407d86eab215f15fcd6fabd803e8cf5e |