-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
bpo-30670: Add pp function to the pprint module #11769
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
Changes from all commits
30152b8
c75298b
e7242c0
52f6ed3
9a7aaed
bb2c055
765a9f9
3f30a20
c286cec
fbae1d0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,7 +33,7 @@ The :mod:`pprint` module defines one class: | |
.. index:: single: ...; placeholder | ||
|
||
.. class:: PrettyPrinter(indent=1, width=80, depth=None, stream=None, *, \ | ||
compact=False) | ||
compact=False, sort_dicts=True) | ||
|
||
Construct a :class:`PrettyPrinter` instance. This constructor understands | ||
several keyword parameters. An output stream may be set using the *stream* | ||
|
@@ -50,11 +50,17 @@ The :mod:`pprint` module defines one class: | |
structure cannot be formatted within the constrained width, a best effort will | ||
be made. If *compact* is false (the default) each item of a long sequence | ||
will be formatted on a separate line. If *compact* is true, as many items | ||
as will fit within the *width* will be formatted on each output line. | ||
as will fit within the *width* will be formatted on each output line. If | ||
*sort_dicts* is true (the default), dictionaries will be formatted with their | ||
keys sorted, otherwise they will display in insertion order. | ||
|
||
.. versionchanged:: 3.4 | ||
Added the *compact* parameter. | ||
|
||
.. versionchanged:: 3.8 | ||
remilapeyre marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Added the *sort_dicts* parameter. | ||
|
||
|
||
>>> import pprint | ||
>>> stuff = ['spam', 'eggs', 'lumberjack', 'knights', 'ni'] | ||
>>> stuff.insert(0, stuff[:]) | ||
|
@@ -81,29 +87,47 @@ The :mod:`pprint` module defines one class: | |
|
||
The :mod:`pprint` module also provides several shortcut functions: | ||
|
||
.. function:: pformat(object, indent=1, width=80, depth=None, *, compact=False) | ||
.. function:: pformat(object, indent=1, width=80, depth=None, *, \ | ||
compact=False, sort_dicts=True) | ||
|
||
Return the formatted representation of *object* as a string. *indent*, | ||
*width*, *depth* and *compact* will be passed to the :class:`PrettyPrinter` | ||
constructor as formatting parameters. | ||
*width*, *depth*, *compact* and *sort_dicts* will be passed to the | ||
:class:`PrettyPrinter` constructor as formatting parameters. | ||
|
||
.. versionchanged:: 3.4 | ||
Added the *compact* parameter. | ||
|
||
.. versionchanged:: 3.8 | ||
Added the *sort_dicts* parameter. | ||
|
||
|
||
.. function:: pp(object, *args, sort_dicts=False, **kwargs) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would it be worth explicitely saying that this is an alias of pprint() with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is already a mention of I would like to also like to avoid giving to much details about There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (if we were to do change what this function does, we would also change the doc, but I'm good with that.) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
At first glance I was puzzled why both As such, the above mentioned docs would have been useful for me personally :-) |
||
|
||
Prints the formatted representation of *object* followed by a newline. | ||
If *sort_dicts* is false (the default), dictionaries will be displayed with | ||
their keys in insertion order, otherwise the dict keys will be sorted. | ||
*args* an *kwargs* will be passed to :func:`pprint` as formatting | ||
parameters. | ||
|
||
.. versionadded:: 3.8 | ||
|
||
|
||
.. function:: pprint(object, stream=None, indent=1, width=80, depth=None, *, \ | ||
compact=False) | ||
compact=False, sort_dicts=True) | ||
|
||
Prints the formatted representation of *object* on *stream*, followed by a | ||
newline. If *stream* is ``None``, ``sys.stdout`` is used. This may be used | ||
in the interactive interpreter instead of the :func:`print` function for | ||
inspecting values (you can even reassign ``print = pprint.pprint`` for use | ||
within a scope). *indent*, *width*, *depth* and *compact* will be passed | ||
to the :class:`PrettyPrinter` constructor as formatting parameters. | ||
within a scope). *indent*, *width*, *depth*, *compact* and *sort_dicts* will | ||
be passed to the :class:`PrettyPrinter` constructor as formatting parameters. | ||
|
||
.. versionchanged:: 3.4 | ||
Added the *compact* parameter. | ||
|
||
.. versionchanged:: 3.8 | ||
Added the *sort_dicts* parameter. | ||
|
||
>>> import pprint | ||
>>> stuff = ['spam', 'eggs', 'lumberjack', 'knights', 'ni'] | ||
>>> stuff.insert(0, stuff) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
`pprint.pp` has been added to pretty-print objects with dictionary | ||
keys being sorted with their insertion order by default. Parameter | ||
remilapeyre marked this conversation as resolved.
Show resolved
Hide resolved
|
||
*sort_dicts* has been added to `pprint.pprint`, `pprint.pformat` and | ||
`pprint.PrettyPrinter`. Contributed by Rémi Lapeyre. |
Uh oh!
There was an error while loading. Please reload this page.