@@ -46,6 +46,8 @@ The :mod:`pprint` module defines one class:
46
46
47
47
*stream * (default ``sys.stdout ``) is a :term: `file-like object ` to
48
48
which the output will be written by calling its :meth: `write ` method.
49
+ If both *stream * and ``sys.stdout `` are ``None ``, then
50
+ :meth: `~PrettyPrinter.pprint ` silently returns.
49
51
50
52
Other values configure the manner in which nesting of complex data
51
53
structures is displayed.
@@ -84,6 +86,9 @@ The :mod:`pprint` module defines one class:
84
86
.. versionchanged :: 3.10
85
87
Added the *underscore_numbers * parameter.
86
88
89
+ .. versionchanged :: 3.11
90
+ No longer attempts to write to ``sys.stdout `` if it is ``None ``.
91
+
87
92
>>> import pprint
88
93
>>> stuff = [' spam' , ' eggs' , ' lumberjack' , ' knights' , ' ni' ]
89
94
>>> stuff.insert(0 , stuff[:])
@@ -107,24 +112,13 @@ The :mod:`pprint` module defines one class:
107
112
>>> pp.pprint(tup)
108
113
('spam', ('eggs', ('lumberjack', ('knights', ('ni', ('dead', (...)))))))
109
114
110
-
111
- The :mod: `pprint ` module also provides several shortcut functions:
112
-
113
115
.. function :: pformat(object, indent=1, width=80, depth=None, *, \
114
116
compact=False, sort_dicts=True, underscore_numbers=False)
115
117
116
118
Return the formatted representation of *object * as a string. *indent *,
117
- *width *, *depth *, *compact *, *sort_dicts * and *underscore_numbers * will be passed to the
118
- :class: `PrettyPrinter ` constructor as formatting parameters.
119
-
120
- .. versionchanged :: 3.4
121
- Added the *compact * parameter.
122
-
123
- .. versionchanged :: 3.8
124
- Added the *sort_dicts * parameter.
125
-
126
- .. versionchanged :: 3.10
127
- Added the *underscore_numbers * parameter.
119
+ *width *, *depth *, *compact *, *sort_dicts * and *underscore_numbers * are
120
+ passed to the :class: `PrettyPrinter ` constructor as formatting parameters
121
+ and their meanings are as described in its documentation above.
128
122
129
123
130
124
.. function :: pp(object, *args, sort_dicts=False, **kwargs)
@@ -142,20 +136,15 @@ The :mod:`pprint` module also provides several shortcut functions:
142
136
compact=False, sort_dicts=True, underscore_numbers=False)
143
137
144
138
Prints the formatted representation of *object * on *stream *, followed by a
145
- newline. If *stream * is ``None ``, ``sys.stdout `` is used. This may be used
139
+ newline. If *stream * is ``None ``, ``sys.stdout `` is used. This may be used
146
140
in the interactive interpreter instead of the :func: `print ` function for
147
141
inspecting values (you can even reassign ``print = pprint.pprint `` for use
148
- within a scope). *indent *, *width *, *depth *, *compact *, *sort_dicts * and *underscore_numbers * will
149
- be passed to the :class: `PrettyPrinter ` constructor as formatting parameters.
150
-
151
- .. versionchanged :: 3.4
152
- Added the *compact * parameter.
153
-
154
- .. versionchanged :: 3.8
155
- Added the *sort_dicts * parameter.
142
+ within a scope).
156
143
157
- .. versionchanged :: 3.10
158
- Added the *underscore_numbers * parameter.
144
+ The configuration parameters *stream *, *indent *, *width *, *depth *,
145
+ *compact *, *sort_dicts * and *underscore_numbers * are passed to the
146
+ :class: `PrettyPrinter ` constructor and their meanings are as
147
+ described in its documentation above.
159
148
160
149
>>> import pprint
161
150
>>> stuff = [' spam' , ' eggs' , ' lumberjack' , ' knights' , ' ni' ]
@@ -168,7 +157,6 @@ The :mod:`pprint` module also provides several shortcut functions:
168
157
'knights',
169
158
'ni']
170
159
171
-
172
160
.. function :: isreadable(object)
173
161
174
162
.. index :: builtin: eval
0 commit comments