Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

GH-115986 Docs: promote pprint.pp usage as a default #116614

Merged
merged 5 commits into from Mar 24, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 8 additions & 5 deletions Doc/library/pprint.rst
Expand Up @@ -61,6 +61,9 @@ Functions
:class:`PrettyPrinter` constructor and their meanings are as
described in its documentation below.

Note that *sort_dicts* default is ``True`` and you might want to use
:func:`~pprint.pp` instead.::
Privat33r-dev marked this conversation as resolved.
Show resolved Hide resolved

>>> import pprint
>>> stuff = ['spam', 'eggs', 'lumberjack', 'knights', 'ni']
>>> stuff.insert(0, stuff)
Expand Down Expand Up @@ -261,7 +264,7 @@ are converted to strings. The default implementation uses the internals of the
Example
-------

To demonstrate several uses of the :func:`~pprint.pprint` function and its parameters,
To demonstrate several uses of the :func:`~pprint.pp` function and its parameters,
let's fetch information about a project from `PyPI <https://pypi.org>`_::

>>> import json
Expand All @@ -270,9 +273,9 @@ let's fetch information about a project from `PyPI <https://pypi.org>`_::
>>> with urlopen('https://pypi.org/pypi/sampleproject/json') as resp:
... project_info = json.load(resp)['info']

In its basic form, :func:`~pprint.pprint` shows the whole object::
In its basic form, :func:`~pprint.pp` shows the whole object::

>>> pprint.pprint(project_info)
>>> pprint.pp(project_info)
{'author': 'The Python Packaging Authority',
'author_email': 'pypa-dev@googlegroups.com',
'bugtrack_url': None,
Expand Down Expand Up @@ -329,7 +332,7 @@ In its basic form, :func:`~pprint.pprint` shows the whole object::
The result can be limited to a certain *depth* (ellipsis is used for deeper
contents)::

>>> pprint.pprint(project_info, depth=1)
>>> pprint.pp(project_info, depth=1)
{'author': 'The Python Packaging Authority',
'author_email': 'pypa-dev@googlegroups.com',
'bugtrack_url': None,
Expand Down Expand Up @@ -375,7 +378,7 @@ contents)::
Additionally, maximum character *width* can be suggested. If a long object
cannot be split, the specified width will be exceeded::

>>> pprint.pprint(project_info, depth=1, width=60)
>>> pprint.pp(project_info, depth=1, width=60)
{'author': 'The Python Packaging Authority',
'author_email': 'pypa-dev@googlegroups.com',
'bugtrack_url': None,
Expand Down