annotate Doc/library/pprint.rst @ 78069:a8aa77458e12 3.2

Add c_size_t and c_ssize_t to the ctypes summary table.
author Antoine Pitrou <solipsis@pitrou.net>
date Thu, 12 Jul 2012 20:31:50 +0200
parents f290cba000ec
children 5a2296093645
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
42604
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
1 :mod:`pprint` --- Data pretty printer
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
2 =====================================
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
3
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
4 .. module:: pprint
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
5 :synopsis: Data pretty printer.
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
6 .. moduleauthor:: Fred L. Drake, Jr. <fdrake@acm.org>
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
7 .. sectionauthor:: Fred L. Drake, Jr. <fdrake@acm.org>
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
8
67501
974b27c9d849 Move source links to consistent location and remove wordy, big yellow boxes.
Raymond Hettinger <python@rcn.com>
parents: 66209
diff changeset
9 **Source code:** :source:`Lib/pprint.py`
42604
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
10
67504
c4a52526e77f Separate source link from main text.
Raymond Hettinger <python@rcn.com>
parents: 67501
diff changeset
11 --------------
42604
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
12
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
13 The :mod:`pprint` module provides a capability to "pretty-print" arbitrary
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
14 Python data structures in a form which can be used as input to the interpreter.
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
15 If the formatted structures include objects which are not fundamental Python
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
16 types, the representation may not be loadable. This may be the case if objects
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
17 such as files, sockets, classes, or instances are included, as well as many
55580
7b495c8f2a24 Merged revisions 73941-73943,74076,74094,74186,74211-74214,74247,74254,74262,74311,74334,74368 via svnmerge from
Georg Brandl <georg@python.org>
parents: 48493
diff changeset
18 other built-in objects which are not representable as Python constants.
42604
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
19
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
20 The formatted representation keeps objects on a single line if it can, and
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
21 breaks them onto multiple lines if they don't fit within the allowed width.
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
22 Construct :class:`PrettyPrinter` objects explicitly if you need to adjust the
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
23 width constraint.
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
24
43176
808f32a0d99c Get rid of the remaining versionadded/versionchanged directives.
Georg Brandl <georg@python.org>
parents: 42604
diff changeset
25 Dictionaries are sorted by key before the display is computed.
42604
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
26
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
27 The :mod:`pprint` module defines one class:
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
28
44396
6556f3f22c19 Merged revisions 59605-59624 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44187
diff changeset
29 .. First the implementation class:
42604
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
30
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
31
55802
106ee4eb5970 Switch more function arguments docs to new-style.
Georg Brandl <georg@python.org>
parents: 55580
diff changeset
32 .. class:: PrettyPrinter(indent=1, width=80, depth=None, stream=None)
42604
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
33
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
34 Construct a :class:`PrettyPrinter` instance. This constructor understands
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
35 several keyword parameters. An output stream may be set using the *stream*
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
36 keyword; the only method used on the stream object is the file protocol's
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
37 :meth:`write` method. If not specified, the :class:`PrettyPrinter` adopts
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
38 ``sys.stdout``. Three additional parameters may be used to control the
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
39 formatted representation. The keywords are *indent*, *depth*, and *width*. The
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
40 amount of indentation added for each recursive level is specified by *indent*;
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
41 the default is one. Other values can cause output to look a little odd, but can
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
42 make nesting easier to spot. The number of levels which may be printed is
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
43 controlled by *depth*; if the data structure being printed is too deep, the next
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
44 contained level is replaced by ``...``. By default, there is no constraint on
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
45 the depth of the objects being formatted. The desired output width is
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
46 constrained using the *width* parameter; the default is 80 characters. If a
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
47 structure cannot be formatted within the constrained width, a best effort will
46034
0a485593ae1c Merged revisions 61724-61725,61731-61735,61737,61739,61741,61743-61744,61753,61761,61765-61767,61769,61773,61776-61778,61780-61783,61788,61793,61796,61807,61813 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44885
diff changeset
48 be made.
42604
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
49
44187
05da49eb12c1 Merged revisions 59333-59370 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43219
diff changeset
50 >>> import pprint
05da49eb12c1 Merged revisions 59333-59370 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43219
diff changeset
51 >>> stuff = ['spam', 'eggs', 'lumberjack', 'knights', 'ni']
42604
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
52 >>> stuff.insert(0, stuff[:])
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
53 >>> pp = pprint.PrettyPrinter(indent=4)
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
54 >>> pp.pprint(stuff)
48493
9ebd3f385575 Merged revisions 64446,64490,64495,64526,64567 via svnmerge from
Georg Brandl <georg@python.org>
parents: 47080
diff changeset
55 [ ['spam', 'eggs', 'lumberjack', 'knights', 'ni'],
44187
05da49eb12c1 Merged revisions 59333-59370 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43219
diff changeset
56 'spam',
05da49eb12c1 Merged revisions 59333-59370 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43219
diff changeset
57 'eggs',
05da49eb12c1 Merged revisions 59333-59370 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43219
diff changeset
58 'lumberjack',
05da49eb12c1 Merged revisions 59333-59370 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43219
diff changeset
59 'knights',
05da49eb12c1 Merged revisions 59333-59370 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43219
diff changeset
60 'ni']
05da49eb12c1 Merged revisions 59333-59370 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43219
diff changeset
61 >>> tup = ('spam', ('eggs', ('lumberjack', ('knights', ('ni', ('dead',
05da49eb12c1 Merged revisions 59333-59370 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43219
diff changeset
62 ... ('parrot', ('fresh fruit',))))))))
42604
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
63 >>> pp = pprint.PrettyPrinter(depth=6)
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
64 >>> pp.pprint(tup)
47080
58a0d5524f9a Merged revisions 63119-63128,63130-63131,63133,63135-63144,63146-63148,63151-63152,63155-63165,63167-63176,63181-63186,63188-63189 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 46539
diff changeset
65 ('spam', ('eggs', ('lumberjack', ('knights', ('ni', ('dead', (...)))))))
42604
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
66
55802
106ee4eb5970 Switch more function arguments docs to new-style.
Georg Brandl <georg@python.org>
parents: 55580
diff changeset
67
42604
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
68 The :class:`PrettyPrinter` class supports several derivative functions:
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
69
55802
106ee4eb5970 Switch more function arguments docs to new-style.
Georg Brandl <georg@python.org>
parents: 55580
diff changeset
70 .. function:: pformat(object, indent=1, width=80, depth=None)
42604
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
71
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
72 Return the formatted representation of *object* as a string. *indent*, *width*
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
73 and *depth* will be passed to the :class:`PrettyPrinter` constructor as
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
74 formatting parameters.
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
75
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
76
55802
106ee4eb5970 Switch more function arguments docs to new-style.
Georg Brandl <georg@python.org>
parents: 55580
diff changeset
77 .. function:: pprint(object, stream=None, indent=1, width=80, depth=None)
42604
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
78
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
79 Prints the formatted representation of *object* on *stream*, followed by a
55802
106ee4eb5970 Switch more function arguments docs to new-style.
Georg Brandl <georg@python.org>
parents: 55580
diff changeset
80 newline. If *stream* is ``None``, ``sys.stdout`` is used. This may be used
43219
655071bf6c45 Convert all print statements in the docs.
Georg Brandl <georg@python.org>
parents: 43176
diff changeset
81 in the interactive interpreter instead of the :func:`print` function for
655071bf6c45 Convert all print statements in the docs.
Georg Brandl <georg@python.org>
parents: 43176
diff changeset
82 inspecting values (you can even reassign ``print = pprint.pprint`` for use
655071bf6c45 Convert all print statements in the docs.
Georg Brandl <georg@python.org>
parents: 43176
diff changeset
83 within a scope). *indent*, *width* and *depth* will be passed to the
46034
0a485593ae1c Merged revisions 61724-61725,61731-61735,61737,61739,61741,61743-61744,61753,61761,61765-61767,61769,61773,61776-61778,61780-61783,61788,61793,61796,61807,61813 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44885
diff changeset
84 :class:`PrettyPrinter` constructor as formatting parameters.
42604
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
85
44187
05da49eb12c1 Merged revisions 59333-59370 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43219
diff changeset
86 >>> import pprint
05da49eb12c1 Merged revisions 59333-59370 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43219
diff changeset
87 >>> stuff = ['spam', 'eggs', 'lumberjack', 'knights', 'ni']
42604
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
88 >>> stuff.insert(0, stuff)
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
89 >>> pprint.pprint(stuff)
46034
0a485593ae1c Merged revisions 61724-61725,61731-61735,61737,61739,61741,61743-61744,61753,61761,61765-61767,61769,61773,61776-61778,61780-61783,61788,61793,61796,61807,61813 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44885
diff changeset
90 [<Recursion on list with id=...>,
0a485593ae1c Merged revisions 61724-61725,61731-61735,61737,61739,61741,61743-61744,61753,61761,61765-61767,61769,61773,61776-61778,61780-61783,61788,61793,61796,61807,61813 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44885
diff changeset
91 'spam',
0a485593ae1c Merged revisions 61724-61725,61731-61735,61737,61739,61741,61743-61744,61753,61761,61765-61767,61769,61773,61776-61778,61780-61783,61788,61793,61796,61807,61813 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44885
diff changeset
92 'eggs',
0a485593ae1c Merged revisions 61724-61725,61731-61735,61737,61739,61741,61743-61744,61753,61761,61765-61767,61769,61773,61776-61778,61780-61783,61788,61793,61796,61807,61813 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44885
diff changeset
93 'lumberjack',
0a485593ae1c Merged revisions 61724-61725,61731-61735,61737,61739,61741,61743-61744,61753,61761,61765-61767,61769,61773,61776-61778,61780-61783,61788,61793,61796,61807,61813 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44885
diff changeset
94 'knights',
0a485593ae1c Merged revisions 61724-61725,61731-61735,61737,61739,61741,61743-61744,61753,61761,61765-61767,61769,61773,61776-61778,61780-61783,61788,61793,61796,61807,61813 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44885
diff changeset
95 'ni']
42604
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
96
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
97
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
98 .. function:: isreadable(object)
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
99
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
100 .. index:: builtin: eval
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
101
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
102 Determine if the formatted representation of *object* is "readable," or can be
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
103 used to reconstruct the value using :func:`eval`. This always returns ``False``
46034
0a485593ae1c Merged revisions 61724-61725,61731-61735,61737,61739,61741,61743-61744,61753,61761,61765-61767,61769,61773,61776-61778,61780-61783,61788,61793,61796,61807,61813 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44885
diff changeset
104 for recursive objects.
42604
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
105
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
106 >>> pprint.isreadable(stuff)
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
107 False
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
108
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
109
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
110 .. function:: isrecursive(object)
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
111
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
112 Determine if *object* requires a recursive representation.
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
113
46034
0a485593ae1c Merged revisions 61724-61725,61731-61735,61737,61739,61741,61743-61744,61753,61761,61765-61767,61769,61773,61776-61778,61780-61783,61788,61793,61796,61807,61813 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44885
diff changeset
114
42604
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
115 One more support function is also defined:
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
116
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
117 .. function:: saferepr(object)
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
118
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
119 Return a string representation of *object*, protected against recursive data
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
120 structures. If the representation of *object* exposes a recursive entry, the
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
121 recursive reference will be represented as ``<Recursion on typename with
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
122 id=number>``. The representation is not otherwise formatted.
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
123
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
124 >>> pprint.saferepr(stuff)
46034
0a485593ae1c Merged revisions 61724-61725,61731-61735,61737,61739,61741,61743-61744,61753,61761,61765-61767,61769,61773,61776-61778,61780-61783,61788,61793,61796,61807,61813 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44885
diff changeset
125 "[<Recursion on list with id=...>, 'spam', 'eggs', 'lumberjack', 'knights', 'ni']"
42604
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
126
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
127
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
128 .. _prettyprinter-objects:
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
129
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
130 PrettyPrinter Objects
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
131 ---------------------
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
132
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
133 :class:`PrettyPrinter` instances have the following methods:
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
134
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
135
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
136 .. method:: PrettyPrinter.pformat(object)
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
137
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
138 Return the formatted representation of *object*. This takes into account the
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
139 options passed to the :class:`PrettyPrinter` constructor.
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
140
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
141
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
142 .. method:: PrettyPrinter.pprint(object)
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
143
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
144 Print the formatted representation of *object* on the configured stream,
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
145 followed by a newline.
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
146
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
147 The following methods provide the implementations for the corresponding
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
148 functions of the same names. Using these methods on an instance is slightly
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
149 more efficient since new :class:`PrettyPrinter` objects don't need to be
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
150 created.
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
151
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
152
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
153 .. method:: PrettyPrinter.isreadable(object)
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
154
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
155 .. index:: builtin: eval
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
156
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
157 Determine if the formatted representation of the object is "readable," or can be
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
158 used to reconstruct the value using :func:`eval`. Note that this returns
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
159 ``False`` for recursive objects. If the *depth* parameter of the
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
160 :class:`PrettyPrinter` is set and the object is deeper than allowed, this
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
161 returns ``False``.
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
162
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
163
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
164 .. method:: PrettyPrinter.isrecursive(object)
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
165
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
166 Determine if the object requires a recursive representation.
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
167
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
168 This method is provided as a hook to allow subclasses to modify the way objects
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
169 are converted to strings. The default implementation uses the internals of the
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
170 :func:`saferepr` implementation.
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
171
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
172
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
173 .. method:: PrettyPrinter.format(object, context, maxlevels, level)
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
174
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
175 Returns three values: the formatted version of *object* as a string, a flag
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
176 indicating whether the result is readable, and a flag indicating whether
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
177 recursion was detected. The first argument is the object to be presented. The
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
178 second is a dictionary which contains the :func:`id` of objects that are part of
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
179 the current presentation context (direct and indirect containers for *object*
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
180 that are affecting the presentation) as the keys; if an object needs to be
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
181 presented which is already represented in *context*, the third return value
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
182 should be ``True``. Recursive calls to the :meth:`format` method should add
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
183 additional entries for containers to this dictionary. The third argument,
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
184 *maxlevels*, gives the requested limit to recursion; this will be ``0`` if there
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
185 is no requested limit. This argument should be passed unmodified to recursive
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
186 calls. The fourth argument, *level*, gives the current level; recursive calls
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
187 should be passed a value less than that of the current call.
44187
05da49eb12c1 Merged revisions 59333-59370 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43219
diff changeset
188
05da49eb12c1 Merged revisions 59333-59370 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43219
diff changeset
189
05da49eb12c1 Merged revisions 59333-59370 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43219
diff changeset
190 .. _pprint-example:
05da49eb12c1 Merged revisions 59333-59370 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43219
diff changeset
191
70106
ab16d8d4f75d pprint usage example rethought.
Łukasz Langa <lukasz@langa.pl>
parents: 55580
diff changeset
192 Example
ab16d8d4f75d pprint usage example rethought.
Łukasz Langa <lukasz@langa.pl>
parents: 55580
diff changeset
193 -------
44187
05da49eb12c1 Merged revisions 59333-59370 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43219
diff changeset
194
70106
ab16d8d4f75d pprint usage example rethought.
Łukasz Langa <lukasz@langa.pl>
parents: 55580
diff changeset
195 To demonstrate several uses of the :func:`pprint` function and its parameters,
70492
44934c1ec145 Don’t misuse “package data” in pprint example
Éric Araujo <merwok@netwok.org>
parents: 70106
diff changeset
196 let's fetch information about a project from PyPI::
44187
05da49eb12c1 Merged revisions 59333-59370 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43219
diff changeset
197
70106
ab16d8d4f75d pprint usage example rethought.
Łukasz Langa <lukasz@langa.pl>
parents: 55580
diff changeset
198 >>> import json
44187
05da49eb12c1 Merged revisions 59333-59370 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43219
diff changeset
199 >>> import pprint
70106
ab16d8d4f75d pprint usage example rethought.
Łukasz Langa <lukasz@langa.pl>
parents: 55580
diff changeset
200 >>> from urllib.request import urlopen
ab16d8d4f75d pprint usage example rethought.
Łukasz Langa <lukasz@langa.pl>
parents: 55580
diff changeset
201 >>> with urlopen('http://pypi.python.org/pypi/configparser/json') as url:
ab16d8d4f75d pprint usage example rethought.
Łukasz Langa <lukasz@langa.pl>
parents: 55580
diff changeset
202 ... http_info = url.info()
ab16d8d4f75d pprint usage example rethought.
Łukasz Langa <lukasz@langa.pl>
parents: 55580
diff changeset
203 ... raw_data = url.read().decode(http_info.get_content_charset())
70492
44934c1ec145 Don’t misuse “package data” in pprint example
Éric Araujo <merwok@netwok.org>
parents: 70106
diff changeset
204 >>> project_info = json.loads(raw_data)
44934c1ec145 Don’t misuse “package data” in pprint example
Éric Araujo <merwok@netwok.org>
parents: 70106
diff changeset
205 >>> result = {'headers': http_info.items(), 'body': project_info}
70106
ab16d8d4f75d pprint usage example rethought.
Łukasz Langa <lukasz@langa.pl>
parents: 55580
diff changeset
206
ab16d8d4f75d pprint usage example rethought.
Łukasz Langa <lukasz@langa.pl>
parents: 55580
diff changeset
207 In its basic form, :func:`pprint` shows the whole object::
44187
05da49eb12c1 Merged revisions 59333-59370 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43219
diff changeset
208
70106
ab16d8d4f75d pprint usage example rethought.
Łukasz Langa <lukasz@langa.pl>
parents: 55580
diff changeset
209 >>> pprint.pprint(result)
ab16d8d4f75d pprint usage example rethought.
Łukasz Langa <lukasz@langa.pl>
parents: 55580
diff changeset
210 {'body': {'info': {'_pypi_hidden': False,
ab16d8d4f75d pprint usage example rethought.
Łukasz Langa <lukasz@langa.pl>
parents: 55580
diff changeset
211 '_pypi_ordering': 12,
ab16d8d4f75d pprint usage example rethought.
Łukasz Langa <lukasz@langa.pl>
parents: 55580
diff changeset
212 'classifiers': ['Development Status :: 4 - Beta',
ab16d8d4f75d pprint usage example rethought.
Łukasz Langa <lukasz@langa.pl>
parents: 55580
diff changeset
213 'Intended Audience :: Developers',
ab16d8d4f75d pprint usage example rethought.
Łukasz Langa <lukasz@langa.pl>
parents: 55580
diff changeset
214 'License :: OSI Approved :: MIT License',
ab16d8d4f75d pprint usage example rethought.
Łukasz Langa <lukasz@langa.pl>
parents: 55580
diff changeset
215 'Natural Language :: English',
ab16d8d4f75d pprint usage example rethought.
Łukasz Langa <lukasz@langa.pl>
parents: 55580
diff changeset
216 'Operating System :: OS Independent',
ab16d8d4f75d pprint usage example rethought.
Łukasz Langa <lukasz@langa.pl>
parents: 55580
diff changeset
217 'Programming Language :: Python',
ab16d8d4f75d pprint usage example rethought.
Łukasz Langa <lukasz@langa.pl>
parents: 55580
diff changeset
218 'Programming Language :: Python :: 2',
ab16d8d4f75d pprint usage example rethought.
Łukasz Langa <lukasz@langa.pl>
parents: 55580
diff changeset
219 'Programming Language :: Python :: 2.6',
ab16d8d4f75d pprint usage example rethought.
Łukasz Langa <lukasz@langa.pl>
parents: 55580
diff changeset
220 'Programming Language :: Python :: 2.7',
ab16d8d4f75d pprint usage example rethought.
Łukasz Langa <lukasz@langa.pl>
parents: 55580
diff changeset
221 'Topic :: Software Development :: Libraries',
ab16d8d4f75d pprint usage example rethought.
Łukasz Langa <lukasz@langa.pl>
parents: 55580
diff changeset
222 'Topic :: Software Development :: Libraries :: Python Modules'],
ab16d8d4f75d pprint usage example rethought.
Łukasz Langa <lukasz@langa.pl>
parents: 55580
diff changeset
223 'download_url': 'UNKNOWN',
ab16d8d4f75d pprint usage example rethought.
Łukasz Langa <lukasz@langa.pl>
parents: 55580
diff changeset
224 'home_page': 'http://docs.python.org/py3k/library/configparser.html',
ab16d8d4f75d pprint usage example rethought.
Łukasz Langa <lukasz@langa.pl>
parents: 55580
diff changeset
225 'keywords': 'configparser ini parsing conf cfg configuration file',
ab16d8d4f75d pprint usage example rethought.
Łukasz Langa <lukasz@langa.pl>
parents: 55580
diff changeset
226 'license': 'MIT',
ab16d8d4f75d pprint usage example rethought.
Łukasz Langa <lukasz@langa.pl>
parents: 55580
diff changeset
227 'name': 'configparser',
ab16d8d4f75d pprint usage example rethought.
Łukasz Langa <lukasz@langa.pl>
parents: 55580
diff changeset
228 'package_url': 'http://pypi.python.org/pypi/configparser',
ab16d8d4f75d pprint usage example rethought.
Łukasz Langa <lukasz@langa.pl>
parents: 55580
diff changeset
229 'platform': 'any',
ab16d8d4f75d pprint usage example rethought.
Łukasz Langa <lukasz@langa.pl>
parents: 55580
diff changeset
230 'release_url': 'http://pypi.python.org/pypi/configparser/3.2.0r3',
ab16d8d4f75d pprint usage example rethought.
Łukasz Langa <lukasz@langa.pl>
parents: 55580
diff changeset
231 'requires_python': None,
ab16d8d4f75d pprint usage example rethought.
Łukasz Langa <lukasz@langa.pl>
parents: 55580
diff changeset
232 'stable_version': None,
ab16d8d4f75d pprint usage example rethought.
Łukasz Langa <lukasz@langa.pl>
parents: 55580
diff changeset
233 'summary': 'This library brings the updated configparser from Python 3.2+ to Python 2.6-2.7.',
ab16d8d4f75d pprint usage example rethought.
Łukasz Langa <lukasz@langa.pl>
parents: 55580
diff changeset
234 'version': '3.2.0r3'},
ab16d8d4f75d pprint usage example rethought.
Łukasz Langa <lukasz@langa.pl>
parents: 55580
diff changeset
235 'urls': [{'comment_text': '',
ab16d8d4f75d pprint usage example rethought.
Łukasz Langa <lukasz@langa.pl>
parents: 55580
diff changeset
236 'downloads': 47,
ab16d8d4f75d pprint usage example rethought.
Łukasz Langa <lukasz@langa.pl>
parents: 55580
diff changeset
237 'filename': 'configparser-3.2.0r3.tar.gz',
ab16d8d4f75d pprint usage example rethought.
Łukasz Langa <lukasz@langa.pl>
parents: 55580
diff changeset
238 'has_sig': False,
ab16d8d4f75d pprint usage example rethought.
Łukasz Langa <lukasz@langa.pl>
parents: 55580
diff changeset
239 'md5_digest': '8500fd87c61ac0de328fc996fce69b96',
ab16d8d4f75d pprint usage example rethought.
Łukasz Langa <lukasz@langa.pl>
parents: 55580
diff changeset
240 'packagetype': 'sdist',
ab16d8d4f75d pprint usage example rethought.
Łukasz Langa <lukasz@langa.pl>
parents: 55580
diff changeset
241 'python_version': 'source',
ab16d8d4f75d pprint usage example rethought.
Łukasz Langa <lukasz@langa.pl>
parents: 55580
diff changeset
242 'size': 32281,
ab16d8d4f75d pprint usage example rethought.
Łukasz Langa <lukasz@langa.pl>
parents: 55580
diff changeset
243 'upload_time': '2011-05-10T16:28:50',
ab16d8d4f75d pprint usage example rethought.
Łukasz Langa <lukasz@langa.pl>
parents: 55580
diff changeset
244 'url': 'http://pypi.python.org/packages/source/c/configparser/configparser-3.2.0r3.tar.gz'}]},
ab16d8d4f75d pprint usage example rethought.
Łukasz Langa <lukasz@langa.pl>
parents: 55580
diff changeset
245 'headers': [('Date', 'Sat, 14 May 2011 12:48:52 GMT'),
ab16d8d4f75d pprint usage example rethought.
Łukasz Langa <lukasz@langa.pl>
parents: 55580
diff changeset
246 ('Server', 'Apache/2.2.16 (Debian)'),
ab16d8d4f75d pprint usage example rethought.
Łukasz Langa <lukasz@langa.pl>
parents: 55580
diff changeset
247 ('Content-Disposition', 'inline'),
ab16d8d4f75d pprint usage example rethought.
Łukasz Langa <lukasz@langa.pl>
parents: 55580
diff changeset
248 ('Connection', 'close'),
ab16d8d4f75d pprint usage example rethought.
Łukasz Langa <lukasz@langa.pl>
parents: 55580
diff changeset
249 ('Transfer-Encoding', 'chunked'),
ab16d8d4f75d pprint usage example rethought.
Łukasz Langa <lukasz@langa.pl>
parents: 55580
diff changeset
250 ('Content-Type', 'application/json; charset="UTF-8"')]}
ab16d8d4f75d pprint usage example rethought.
Łukasz Langa <lukasz@langa.pl>
parents: 55580
diff changeset
251
ab16d8d4f75d pprint usage example rethought.
Łukasz Langa <lukasz@langa.pl>
parents: 55580
diff changeset
252 The result can be limited to a certain *depth* (ellipsis is used for deeper
ab16d8d4f75d pprint usage example rethought.
Łukasz Langa <lukasz@langa.pl>
parents: 55580
diff changeset
253 contents)::
ab16d8d4f75d pprint usage example rethought.
Łukasz Langa <lukasz@langa.pl>
parents: 55580
diff changeset
254
ab16d8d4f75d pprint usage example rethought.
Łukasz Langa <lukasz@langa.pl>
parents: 55580
diff changeset
255 >>> pprint.pprint(result, depth=3)
ab16d8d4f75d pprint usage example rethought.
Łukasz Langa <lukasz@langa.pl>
parents: 55580
diff changeset
256 {'body': {'info': {'_pypi_hidden': False,
ab16d8d4f75d pprint usage example rethought.
Łukasz Langa <lukasz@langa.pl>
parents: 55580
diff changeset
257 '_pypi_ordering': 12,
ab16d8d4f75d pprint usage example rethought.
Łukasz Langa <lukasz@langa.pl>
parents: 55580
diff changeset
258 'classifiers': [...],
ab16d8d4f75d pprint usage example rethought.
Łukasz Langa <lukasz@langa.pl>
parents: 55580
diff changeset
259 'download_url': 'UNKNOWN',
ab16d8d4f75d pprint usage example rethought.
Łukasz Langa <lukasz@langa.pl>
parents: 55580
diff changeset
260 'home_page': 'http://docs.python.org/py3k/library/configparser.html',
ab16d8d4f75d pprint usage example rethought.
Łukasz Langa <lukasz@langa.pl>
parents: 55580
diff changeset
261 'keywords': 'configparser ini parsing conf cfg configuration file',
ab16d8d4f75d pprint usage example rethought.
Łukasz Langa <lukasz@langa.pl>
parents: 55580
diff changeset
262 'license': 'MIT',
ab16d8d4f75d pprint usage example rethought.
Łukasz Langa <lukasz@langa.pl>
parents: 55580
diff changeset
263 'name': 'configparser',
ab16d8d4f75d pprint usage example rethought.
Łukasz Langa <lukasz@langa.pl>
parents: 55580
diff changeset
264 'package_url': 'http://pypi.python.org/pypi/configparser',
ab16d8d4f75d pprint usage example rethought.
Łukasz Langa <lukasz@langa.pl>
parents: 55580
diff changeset
265 'platform': 'any',
ab16d8d4f75d pprint usage example rethought.
Łukasz Langa <lukasz@langa.pl>
parents: 55580
diff changeset
266 'release_url': 'http://pypi.python.org/pypi/configparser/3.2.0r3',
ab16d8d4f75d pprint usage example rethought.
Łukasz Langa <lukasz@langa.pl>
parents: 55580
diff changeset
267 'requires_python': None,
ab16d8d4f75d pprint usage example rethought.
Łukasz Langa <lukasz@langa.pl>
parents: 55580
diff changeset
268 'stable_version': None,
ab16d8d4f75d pprint usage example rethought.
Łukasz Langa <lukasz@langa.pl>
parents: 55580
diff changeset
269 'summary': 'This library brings the updated configparser from Python 3.2+ to Python 2.6-2.7.',
ab16d8d4f75d pprint usage example rethought.
Łukasz Langa <lukasz@langa.pl>
parents: 55580
diff changeset
270 'version': '3.2.0r3'},
ab16d8d4f75d pprint usage example rethought.
Łukasz Langa <lukasz@langa.pl>
parents: 55580
diff changeset
271 'urls': [{...}]},
ab16d8d4f75d pprint usage example rethought.
Łukasz Langa <lukasz@langa.pl>
parents: 55580
diff changeset
272 'headers': [('Date', 'Sat, 14 May 2011 12:48:52 GMT'),
ab16d8d4f75d pprint usage example rethought.
Łukasz Langa <lukasz@langa.pl>
parents: 55580
diff changeset
273 ('Server', 'Apache/2.2.16 (Debian)'),
ab16d8d4f75d pprint usage example rethought.
Łukasz Langa <lukasz@langa.pl>
parents: 55580
diff changeset
274 ('Content-Disposition', 'inline'),
ab16d8d4f75d pprint usage example rethought.
Łukasz Langa <lukasz@langa.pl>
parents: 55580
diff changeset
275 ('Connection', 'close'),
ab16d8d4f75d pprint usage example rethought.
Łukasz Langa <lukasz@langa.pl>
parents: 55580
diff changeset
276 ('Transfer-Encoding', 'chunked'),
ab16d8d4f75d pprint usage example rethought.
Łukasz Langa <lukasz@langa.pl>
parents: 55580
diff changeset
277 ('Content-Type', 'application/json; charset="UTF-8"')]}
ab16d8d4f75d pprint usage example rethought.
Łukasz Langa <lukasz@langa.pl>
parents: 55580
diff changeset
278
ab16d8d4f75d pprint usage example rethought.
Łukasz Langa <lukasz@langa.pl>
parents: 55580
diff changeset
279 Additionally, maximum *width* can be suggested. If a long object cannot be
ab16d8d4f75d pprint usage example rethought.
Łukasz Langa <lukasz@langa.pl>
parents: 55580
diff changeset
280 split, the specified width will be exceeded::
ab16d8d4f75d pprint usage example rethought.
Łukasz Langa <lukasz@langa.pl>
parents: 55580
diff changeset
281
ab16d8d4f75d pprint usage example rethought.
Łukasz Langa <lukasz@langa.pl>
parents: 55580
diff changeset
282 >>> pprint.pprint(result['headers'], width=30)
ab16d8d4f75d pprint usage example rethought.
Łukasz Langa <lukasz@langa.pl>
parents: 55580
diff changeset
283 [('Date',
ab16d8d4f75d pprint usage example rethought.
Łukasz Langa <lukasz@langa.pl>
parents: 55580
diff changeset
284 'Sat, 14 May 2011 12:48:52 GMT'),
ab16d8d4f75d pprint usage example rethought.
Łukasz Langa <lukasz@langa.pl>
parents: 55580
diff changeset
285 ('Server',
ab16d8d4f75d pprint usage example rethought.
Łukasz Langa <lukasz@langa.pl>
parents: 55580
diff changeset
286 'Apache/2.2.16 (Debian)'),
ab16d8d4f75d pprint usage example rethought.
Łukasz Langa <lukasz@langa.pl>
parents: 55580
diff changeset
287 ('Content-Disposition',
ab16d8d4f75d pprint usage example rethought.
Łukasz Langa <lukasz@langa.pl>
parents: 55580
diff changeset
288 'inline'),
ab16d8d4f75d pprint usage example rethought.
Łukasz Langa <lukasz@langa.pl>
parents: 55580
diff changeset
289 ('Connection', 'close'),
ab16d8d4f75d pprint usage example rethought.
Łukasz Langa <lukasz@langa.pl>
parents: 55580
diff changeset
290 ('Transfer-Encoding',
ab16d8d4f75d pprint usage example rethought.
Łukasz Langa <lukasz@langa.pl>
parents: 55580
diff changeset
291 'chunked'),
ab16d8d4f75d pprint usage example rethought.
Łukasz Langa <lukasz@langa.pl>
parents: 55580
diff changeset
292 ('Content-Type',
ab16d8d4f75d pprint usage example rethought.
Łukasz Langa <lukasz@langa.pl>
parents: 55580
diff changeset
293 'application/json; charset="UTF-8"')]