@@ -70,18 +70,57 @@ Functions
70
70
The configuration parameters *stream *, *indent *, *width *, *depth *,
71
71
*compact *, *sort_dicts * and *underscore_numbers * are passed to the
72
72
:class: `PrettyPrinter ` constructor and their meanings are as
73
- described in its documentation below.
73
+ described in the documentation below.
74
74
75
75
Note that *sort_dicts * is ``True `` by default and you might want to use
76
76
:func: `~pprint.pp ` instead where it is ``False `` by default.
77
77
78
+ .. _prettyprinter-parameters :
79
+
80
+ .. list-table :: **Recognised parameters for PrettyPrinter**
81
+ :header-rows: 1
82
+ :widths: 20 80
83
+
84
+ * - Parameter
85
+ - Description
86
+ * - ``indent ``: ``int ``
87
+ - The amount of indentation added for each nesting level.
88
+ * - ``width ``: ``int ``
89
+ - The desired maximum number of characters per line in the output.
90
+ If a structure cannot be formatted within the width constraint,
91
+ a best effort will be made.
92
+ * - ``depth ``: ``int `` | ``None ``
93
+ - The number of nesting levels which may be printed.
94
+ If the data structure being printed is too deep,
95
+ the next contained level is replaced by ``... ``.
96
+ If ``None `` (the default), there is no constraint
97
+ on the depth of the objects being formatted.
98
+ * - ``stream ``: :term: `file-like object ` | ``None ``
99
+ - A file-like object to which the output will be written
100
+ by calling its :meth: `!write ` method.
101
+ If ``None `` (the default), :data: `sys.stdout ` is used.
102
+ * - ``compact ``: ``bool ``
103
+ - Control the way long :term: `sequences <sequence> ` are formatted.
104
+ If ``False `` (the default),
105
+ each item of a sequence will be formatted on a separate line,
106
+ otherwise as many items as will fit within the *width *
107
+ will be formatted on each output line.
108
+ * - ``sort_dicts ``: ``bool ``
109
+ - If ``True `` (the default), dictionaries will be formatted with
110
+ their keys sorted, otherwise they will display in insertion order.
111
+ * - ``underscore_numbers ``: ``bool ``
112
+ - If ``True ``,
113
+ integers will be formatted with the ``_ `` character for a thousands separator,
114
+ otherwise underscores are not displayed (the default).
115
+
116
+
78
117
.. function :: pformat(object, indent=1, width=80, depth=None, *, \
79
118
compact=False, sort_dicts=True, underscore_numbers=False)
80
119
81
120
Return the formatted representation of *object * as a string. *indent *,
82
121
*width *, *depth *, *compact *, *sort_dicts * and *underscore_numbers * are
83
122
passed to the :class: `PrettyPrinter ` constructor as formatting parameters
84
- and their meanings are as described in its documentation below .
123
+ and their meanings are as described in the documentation above .
85
124
86
125
87
126
.. function :: isreadable(object)
@@ -120,51 +159,14 @@ Functions
120
159
PrettyPrinter Objects
121
160
---------------------
122
161
123
- This module defines one class:
124
-
125
- .. First the implementation class:
126
-
127
-
128
162
.. index :: single: ...; placeholder
129
163
130
164
.. class :: PrettyPrinter(indent=1, width=80, depth=None, stream=None, *, \
131
165
compact=False, sort_dicts=True, underscore_numbers=False)
132
166
133
167
Construct a :class: `PrettyPrinter ` instance. This constructor understands
134
168
several keyword parameters.
135
-
136
- *stream * (default :data: `!sys.stdout `) is a :term: `file-like object ` to
137
- which the output will be written by calling its :meth: `!write ` method.
138
- If both *stream * and :data: `!sys.stdout ` are ``None ``, then
139
- :meth: `~PrettyPrinter.pprint ` silently returns.
140
-
141
- Other values configure the manner in which nesting of complex data
142
- structures is displayed.
143
-
144
- *indent * (default 1) specifies the amount of indentation added for
145
- each nesting level.
146
-
147
- *depth * controls the number of nesting levels which may be printed; if
148
- the data structure being printed is too deep, the next contained level
149
- is replaced by ``... ``. By default, there is no constraint on the
150
- depth of the objects being formatted.
151
-
152
- *width * (default 80) specifies the desired maximum number of characters per
153
- line in the output. If a structure cannot be formatted within the width
154
- constraint, a best effort will be made.
155
-
156
- *compact * impacts the way that long sequences (lists, tuples, sets, etc)
157
- are formatted. If *compact * is false (the default) then each item of a
158
- sequence will be formatted on a separate line. If *compact * is true, as
159
- many items as will fit within the *width * will be formatted on each output
160
- line.
161
-
162
- If *sort_dicts * is true (the default), dictionaries will be formatted with
163
- their keys sorted, otherwise they will display in insertion order.
164
-
165
- If *underscore_numbers * is true, integers will be formatted with the
166
- ``_ `` character for a thousands separator, otherwise underscores are not
167
- displayed (the default).
169
+ Parameters described at :ref: `parameters table <prettyprinter-parameters >`.
168
170
169
171
.. versionchanged :: 3.4
170
172
Added the *compact * parameter.
0 commit comments