Python
docs.python.org › 3 › library › pprint.html
pprint — Data pretty printer
Generally, including ' 'the project changelog in here is not\n' 'a good idea, although a simple "What\'s ' 'New" section for the most recent version\n' 'may be appropriate.', 'description_content_type': None, 'docs_url': None, 'download_url': 'UNKNOWN', 'downloads': {...}, 'home_page': 'https://github.com/pypa/sampleproject', 'keywords': 'sample setuptools development', 'license': 'MIT', 'maintainer': None, 'maintainer_email': None, 'name': 'sampleproject', 'package_url': 'https://pypi.org/project/sampleproject/', 'platform': 'UNKNOWN', 'project_url': 'https://pypi.org/project/sampleproject/', 'project_urls': {...}, 'release_url': 'https://pypi.org/project/sampleproject/1.2.0/', 'requires_dist': None, 'requires_python': None, 'summary': 'A sample Python project', 'version': '1.2.0'} pprint — Data pretty printer · Functions · PrettyPrinter Objects · Example ·
Real Python
realpython.com › python-pretty-print
Prettify Your Data Structures With Pretty Print in Python – Real Python
October 4, 2022 - It has long been part of the Python standard library, so installing it separately isn’t necessary. All you need to do is to import its pprint() function: ... Then, instead of going with the normal print(users) approach as you did in the example above, you can call your new favorite function ...
Videos
01:59
Python's pprint Module: Mastering Pretty Printing in Python - YouTube
11:03
Python pprint - A Simple Guide to Pretty Printing - YouTube
06:33
Python Pretty Printing pprint - YouTube
01:17
Python Pretty Printing pprint Practical - YouTube
02:22
Python Pretty Print: pprint( ) - YouTube
01:00
Ever used Python’s pprint function? It’s a game-changer - YouTube
Python Module of the Week
pymotw.com › 2 › pprint
pprint – Pretty-print data structures - Python Module of the Week
$ python pprint_width.py WIDTH = 80 [(0, {'a': 'A', 'b': 'B', 'c': 'C'}), (1, {'a': 'A', 'b': 'B', 'c': 'C'}), (2, {'a': 'A', 'b': 'B', 'c': 'C'})] WIDTH = 20 [(0, {'a': 'A', 'b': 'B', 'c': 'C'}), (1, {'a': 'A', 'b': 'B', 'c': 'C'}), (2, {'a': 'A', 'b': 'B', 'c': 'C'})] WIDTH = 5 [(0, {'a': ...
Python Engineer
python-engineer.com › posts › pprint-python
How to use pprint in Python? - Python Engineer
May 17, 2022 - from pprint import pformat nested_dict = [{"language": "Python", "application": ["Data Science", "Automation", "Scraping", "API"]}, {"language": "Javascript", "application": ["Web Development", "API", "Web Apps", "Games"]}] string_representation = pformat(nested_dict) print(string_representation)
GeeksforGeeks
geeksforgeeks.org › pprint-data-pretty-printer-python
pprint : Data pretty printer in Python - GeeksforGeeks
This article provides a quick way to pretty How to Print Dictionary in Python that has a dictionary as values. This is required many times nowadays with the advent of NoSQL databases. Let's code a way to perform this particular task in Python. Example Input:{'gfg': {'remark': 'good', 'rate': 5}, 'c
Published October 6, 2023
Jython
jython.org › jython-old-sites › docs › library › pprint.html
8.18. pprint — Data pretty printer — Jython v2.5.2 documentation
>>> import pprint >>> stuff = ['spam', 'eggs', 'lumberjack', 'knights', 'ni'] >>> stuff.insert(0, stuff) >>> pprint.pprint(stuff) [<Recursion on list with id=...>, 'spam', 'eggs', 'lumberjack', 'knights', 'ni']
TutorialsPoint
tutorialspoint.com › python_text_processing › python_pretty_prints.htm
Python Text Processing - Pretty Printing
import pprint emp = {"Name":["Rick","Dan","Michelle","Ryan","Gary","Nina","Simon","Guru" ], "Salary":["623.3","515.2","611","729","843.25","578","632.8","722.5" ], "StartDate":[ "1/1/2012","9/23/2013","11/15/2014","5/11/2014","3/27/2015","5/21/2013", "7/30/2013","6/17/2014"], "Dept":[ "IT","Operations","IT","HR","Finance","IT","Operations","Finance"] } x= pprint.pformat(emp, indent=2) print(x)
GitHub
github.com › python › cpython › blob › main › Lib › pprint.py
cpython/Lib/pprint.py at main · python/cpython
def pprint(object, stream=None, ... printer = PrettyPrinter( stream=stream, indent=indent, width=width, depth=depth, compact=compact, sort_dicts=sort_dicts, underscore_numbers=underscore_numbers) ...
Author python
Read the Docs
stackless.readthedocs.io › en › 2.7-slp › library › pprint.html
8.18. pprint — Data pretty printer — Stackless-Python 2.7.15 documentation
>>> import pprint >>> tup = ('spam', ('eggs', ('lumberjack', ('knights', ('ni', ('dead', ... ('parrot', ('fresh fruit',)))))))) >>> stuff = ['a' * 10, tup, ['a' * 30, 'b' * 30], ['c' * 20, 'd' * 20]] >>> pprint.pprint(stuff) ['aaaaaaaaaa', ('spam', ('eggs', ('lumberjack', ('knights', ('ni', ('dead', ('parrot', ('fresh fruit',)))))))), ['aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', 'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb'], ['cccccccccccccccccccc', 'dddddddddddddddddddd']] >>> pprint.pprint(stuff, depth=3) ['aaaaaaaaaa', ('spam', ('eggs', (...))), ['aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', 'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb'
W3Schools
w3schools.com › python › ref_module_pprint.asp
Python pprint Module
The pprint module formats Python objects in a way that's easier for humans to read.
Top answer 1 of 6
40
Dan's solution is just wrong, and Ismail's in incomplete.
__str__()is not called,__repr__()is called.__repr__()should return a string, as pformat does.- print normally indents only 1 character and tries to save lines. If you are trying to figure out structure, set the width low and indent high.
Here is an example
class S:
def __repr__(self):
from pprint import pformat
return pformat(vars(self), indent=4, width=1)
a = S()
a.b = 'bee'
a.c = {'cats': ['blacky', 'tiger'], 'dogs': ['rex', 'king'] }
a.d = S()
a.d.more_c = a.c
print(a)
This prints
{ 'b': 'bee',
'c': { 'cats': [ 'blacky',
'tiger'],
'dogs': [ 'rex',
'king']},
'd': { 'more_c': { 'cats': [ 'blacky',
'tiger'],
'dogs': [ 'rex',
'king']}}}
Which is not perfect, but passable.
2 of 6
14
pprint.pprint doesn't return a string; it actually does the printing (by default to stdout, but you can specify an output stream). So when you write print record, record.__str__() gets called, which calls pprint, which returns None. str(None) is 'None', and that gets printed, which is why you see None.
You should use pprint.pformat instead. (Alternatively, you can pass a StringIO instance to pprint.)
Scaler
scaler.com › home › topics › python pprint module
Python Pprint Module - Scaler Topics
May 4, 2023 - In the above example, the string representation of the first user is returned by the function pformat() which can be printed by the print() function. The function pprint() from the module pprint has an alias pp.
Python Module of the Week
pymotw.com › 3 › pprint
pprint — Pretty-Print Data Structures
March 18, 2018 - from pprint import pprint from pprint_data import data print('DEFAULT:') pprint(data, compact=False) print('\nCOMPACT:') pprint(data, compact=True) This example shows that when a data structure does not fit on a line, it is split up (as with the second item in the data list).
seenode blog
seenode.com › blog › how-to-use-python-pretty-print-pprint
How to Use Python Pretty Print (pprint) for Cleaner Python Output | seenode blog
May 19, 2025 - That’s where you need to use a pretty print Python library to get the most visually appealing output. For example: ... You can check that all the key pairs are in a separate row, which allows reading easily. Also, if you check closely, all the elements are automatically sorted according to the keys. The pprintpp ...
Finxter
blog.finxter.com › home › learn python blog › python pprint – a simple guide to pretty printing
Python pprint - A Simple Guide to Pretty Printing - Be on the Right Side of Change
October 18, 2022 - Think of dictionaries in Python to get an idea of the format for JSON – “key”/”value” pairs. The “keys” always being strings, the “values” include ints, Bools, arrays, none, and other objects. There are multiple ways to get data for this type of project – I found a JSON file on employees for a dummy company that I will use for this lesson. You can also use request from the urllib module to get mock data. Let’s get into some code and see pprint in action.