-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
GH-115986 Docs: promote pprint.pp usage as a default #116614
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βll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
394fe0f
Docs: promote pprint.pp usage as a default
Privat33r-dev 6bc4a6f
fix tests, move example
Privat33r-dev 9a78e6e
fix example
Privat33r-dev c17b1d5
Merge branch 'main' into pp-as-default-115986
Privat33r-dev 16252cd
Make 'pprint.pp's suggestion conciser
Privat33r-dev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,6 +44,17 @@ Functions | |
*args* and *kwargs* will be passed to :func:`~pprint.pprint` as formatting | ||
parameters. | ||
|
||
>>> import pprint | ||
>>> stuff = ['spam', 'eggs', 'lumberjack', 'knights', 'ni'] | ||
>>> stuff.insert(0, stuff) | ||
>>> pprint.pp(stuff) | ||
[<Recursion on list with id=...>, | ||
'spam', | ||
'eggs', | ||
'lumberjack', | ||
'knights', | ||
'ni'] | ||
|
||
.. versionadded:: 3.8 | ||
|
||
|
||
|
@@ -61,16 +72,8 @@ Functions | |
:class:`PrettyPrinter` constructor and their meanings are as | ||
described in its documentation below. | ||
|
||
>>> 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'] | ||
Note that *sort_dicts* is ``True`` by default and you might want to use | ||
:func:`~pprint.pp` instead where it is ``False`` by default. | ||
|
||
.. function:: pformat(object, indent=1, width=80, depth=None, *, \ | ||
compact=False, sort_dicts=True, underscore_numbers=False) | ||
|
@@ -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 | ||
|
@@ -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': '[email protected]', | ||
'bugtrack_url': None, | ||
|
@@ -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': '[email protected]', | ||
'bugtrack_url': None, | ||
|
@@ -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': '[email protected]', | ||
'bugtrack_url': None, | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.