Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 193a24b

Browse filesBrowse files
miss-islingtonPrivat33r-devhugovk
authored
[3.12] GH-115986 Docs: promote pprint.pp usage as a default (GH-116614) (#117196)
Co-authored-by: Kerim Kabirov <the.privat33r+gh@pm.me> Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
1 parent 4326e07 commit 193a24b
Copy full SHA for 193a24b

File tree

Expand file treeCollapse file tree

1 file changed

+18
-15
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+18
-15
lines changed

‎Doc/library/pprint.rst

Copy file name to clipboardExpand all lines: Doc/library/pprint.rst
+18-15Lines 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)
@@ -261,7 +264,7 @@ are converted to strings. The default implementation uses the internals of the
261264
Example
262265
-------
263266

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

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

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

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

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

378-
>>> pprint.pprint(project_info, depth=1, width=60)
381+
>>> pprint.pp(project_info, depth=1, width=60)
379382
{'author': 'The Python Packaging Authority',
380383
'author_email': 'pypa-dev@googlegroups.com',
381384
'bugtrack_url': None,

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.