Skip to content

Commit a3a0ce1

Browse files
miss-islingtonPrivat33r-devhugovk
authored
[3.11] GH-115986 Docs: promote pprint.pp usage as a default (GH-116614) (#117197)
Co-authored-by: Kerim Kabirov <[email protected]> Co-authored-by: Hugo van Kemenade <[email protected]>
1 parent 5d12230 commit a3a0ce1

File tree

1 file changed

+18
-15
lines changed

1 file changed

+18
-15
lines changed

Doc/library/pprint.rst

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,17 @@ Functions
4444
*args* and *kwargs* will be passed to :func:`~pprint.pprint` as formatting
4545
parameters.
4646

47+
>>> import pprint
48+
>>> stuff = ['spam', 'eggs', 'lumberjack', 'knights', 'ni']
49+
>>> stuff.insert(0, stuff)
50+
>>> pprint.pp(stuff)
51+
[<Recursion on list with id=...>,
52+
'spam',
53+
'eggs',
54+
'lumberjack',
55+
'knights',
56+
'ni']
57+
4758
.. versionadded:: 3.8
4859

4960

@@ -61,16 +72,8 @@ Functions
6172
:class:`PrettyPrinter` constructor and their meanings are as
6273
described in its documentation below.
6374

64-
>>> import pprint
65-
>>> stuff = ['spam', 'eggs', 'lumberjack', 'knights', 'ni']
66-
>>> stuff.insert(0, stuff)
67-
>>> pprint.pprint(stuff)
68-
[<Recursion on list with id=...>,
69-
'spam',
70-
'eggs',
71-
'lumberjack',
72-
'knights',
73-
'ni']
75+
Note that *sort_dicts* is ``True`` by default and you might want to use
76+
:func:`~pprint.pp` instead where it is ``False`` by default.
7477

7578
.. function:: pformat(object, indent=1, width=80, depth=None, *, \
7679
compact=False, sort_dicts=True, underscore_numbers=False)
@@ -258,7 +261,7 @@ are converted to strings. The default implementation uses the internals of the
258261
Example
259262
-------
260263

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

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

270-
In its basic form, :func:`~pprint.pprint` shows the whole object::
273+
In its basic form, :func:`~pprint.pp` shows the whole object::
271274

272-
>>> pprint.pprint(project_info)
275+
>>> pprint.pp(project_info)
273276
{'author': 'The Python Packaging Authority',
274277
'author_email': '[email protected]',
275278
'bugtrack_url': None,
@@ -326,7 +329,7 @@ In its basic form, :func:`~pprint.pprint` shows the whole object::
326329
The result can be limited to a certain *depth* (ellipsis is used for deeper
327330
contents)::
328331

329-
>>> pprint.pprint(project_info, depth=1)
332+
>>> pprint.pp(project_info, depth=1)
330333
{'author': 'The Python Packaging Authority',
331334
'author_email': '[email protected]',
332335
'bugtrack_url': None,
@@ -372,7 +375,7 @@ contents)::
372375
Additionally, maximum character *width* can be suggested. If a long object
373376
cannot be split, the specified width will be exceeded::
374377

375-
>>> pprint.pprint(project_info, depth=1, width=60)
378+
>>> pprint.pp(project_info, depth=1, width=60)
376379
{'author': 'The Python Packaging Authority',
377380
'author_email': '[email protected]',
378381
'bugtrack_url': None,

0 commit comments

Comments
 (0)