annotate Doc/library/pprint.rst @ 87690:66c1c9f32567 default tip

Add use_weakref option to functools.lru_cache The use_weakref option makes lru_cache create weak references to the function arguments when creating the cache key, which prevents them from staying in the memory forever even after all other references to them are gone. This is a proof of concept for http://bugs.python.org/issue19859
author Radomir Dopieralski <devel@sheep.art.pl>
date Tue, 03 Dec 2013 16:02:48 +0100
parents 6e7b1aadea2f
children
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
82919
5a2296093645 Issue #17150: pprint now uses line continuations to wrap long string literals.
Antoine Pitrou <solipsis@pitrou.net>
parents: 70496
diff changeset
17 such as files, sockets or classes are included, as well as many other
5a2296093645 Issue #17150: pprint now uses line continuations to wrap long string literals.
Antoine Pitrou <solipsis@pitrou.net>
parents: 70496
diff changeset
18 objects which are not representable as Python literals.
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
85921
ae0306c8f7a3 Issue #19132: The pprint module now supports compact mode.
Serhiy Storchaka <storchaka@gmail.com>
parents: 82919
diff changeset
32 .. class:: PrettyPrinter(indent=1, width=80, depth=None, stream=None, *, \
ae0306c8f7a3 Issue #19132: The pprint module now supports compact mode.
Serhiy Storchaka <storchaka@gmail.com>
parents: 82919
diff changeset
33 compact=False)
42604
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
34
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
35 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
36 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
37 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
38 :meth:`write` method. If not specified, the :class:`PrettyPrinter` adopts
85921
ae0306c8f7a3 Issue #19132: The pprint module now supports compact mode.
Serhiy Storchaka <storchaka@gmail.com>
parents: 82919
diff changeset
39 ``sys.stdout``. The
42604
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
85921
ae0306c8f7a3 Issue #19132: The pprint module now supports compact mode.
Serhiy Storchaka <storchaka@gmail.com>
parents: 82919
diff changeset
48 be made. If *compact* is false (the default) each item of a long sequence
ae0306c8f7a3 Issue #19132: The pprint module now supports compact mode.
Serhiy Storchaka <storchaka@gmail.com>
parents: 82919
diff changeset
49 will be formatted on a separate line. If *compact* is true, as many items
ae0306c8f7a3 Issue #19132: The pprint module now supports compact mode.
Serhiy Storchaka <storchaka@gmail.com>
parents: 82919
diff changeset
50 as will fit within the *width* will be formatted on each output line.
42604
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
51
85932
6e7b1aadea2f Issue #19132: Add versionchanged tags.
Serhiy Storchaka <storchaka@gmail.com>
parents: 85921
diff changeset
52 .. versionchanged:: 3.4
6e7b1aadea2f Issue #19132: Add versionchanged tags.
Serhiy Storchaka <storchaka@gmail.com>
parents: 85921
diff changeset
53 Added the *compact* parameter.
6e7b1aadea2f Issue #19132: Add versionchanged tags.
Serhiy Storchaka <storchaka@gmail.com>
parents: 85921
diff changeset
54
44187
05da49eb12c1 Merged revisions 59333-59370 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43219
diff changeset
55 >>> import pprint
05da49eb12c1 Merged revisions 59333-59370 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43219
diff changeset
56 >>> stuff = ['spam', 'eggs', 'lumberjack', 'knights', 'ni']
42604
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
57 >>> stuff.insert(0, stuff[:])
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
58 >>> pp = pprint.PrettyPrinter(indent=4)
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
59 >>> pp.pprint(stuff)
48493
9ebd3f385575 Merged revisions 64446,64490,64495,64526,64567 via svnmerge from
Georg Brandl <georg@python.org>
parents: 47080
diff changeset
60 [ ['spam', 'eggs', 'lumberjack', 'knights', 'ni'],
44187
05da49eb12c1 Merged revisions 59333-59370 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43219
diff changeset
61 'spam',
05da49eb12c1 Merged revisions 59333-59370 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43219
diff changeset
62 'eggs',
05da49eb12c1 Merged revisions 59333-59370 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43219
diff changeset
63 'lumberjack',
05da49eb12c1 Merged revisions 59333-59370 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43219
diff changeset
64 'knights',
05da49eb12c1 Merged revisions 59333-59370 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43219
diff changeset
65 'ni']
85921
ae0306c8f7a3 Issue #19132: The pprint module now supports compact mode.
Serhiy Storchaka <storchaka@gmail.com>
parents: 82919
diff changeset
66 >>> pp = pprint.PrettyPrinter(width=41, compact=True)
ae0306c8f7a3 Issue #19132: The pprint module now supports compact mode.
Serhiy Storchaka <storchaka@gmail.com>
parents: 82919
diff changeset
67 >>> pp.pprint(stuff)
ae0306c8f7a3 Issue #19132: The pprint module now supports compact mode.
Serhiy Storchaka <storchaka@gmail.com>
parents: 82919
diff changeset
68 [['spam', 'eggs', 'lumberjack',
ae0306c8f7a3 Issue #19132: The pprint module now supports compact mode.
Serhiy Storchaka <storchaka@gmail.com>
parents: 82919
diff changeset
69 'knights', 'ni'],
ae0306c8f7a3 Issue #19132: The pprint module now supports compact mode.
Serhiy Storchaka <storchaka@gmail.com>
parents: 82919
diff changeset
70 'spam', 'eggs', 'lumberjack', 'knights',
ae0306c8f7a3 Issue #19132: The pprint module now supports compact mode.
Serhiy Storchaka <storchaka@gmail.com>
parents: 82919
diff changeset
71 'ni']
44187
05da49eb12c1 Merged revisions 59333-59370 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43219
diff changeset
72 >>> tup = ('spam', ('eggs', ('lumberjack', ('knights', ('ni', ('dead',
05da49eb12c1 Merged revisions 59333-59370 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43219
diff changeset
73 ... ('parrot', ('fresh fruit',))))))))
42604
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
74 >>> pp = pprint.PrettyPrinter(depth=6)
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
75 >>> 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
76 ('spam', ('eggs', ('lumberjack', ('knights', ('ni', ('dead', (...)))))))
42604
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
77
55802
106ee4eb5970 Switch more function arguments docs to new-style.
Georg Brandl <georg@python.org>
parents: 55580
diff changeset
78
82919
5a2296093645 Issue #17150: pprint now uses line continuations to wrap long string literals.
Antoine Pitrou <solipsis@pitrou.net>
parents: 70496
diff changeset
79 The :mod:`pprint` module also provides several shortcut functions:
42604
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
80
85921
ae0306c8f7a3 Issue #19132: The pprint module now supports compact mode.
Serhiy Storchaka <storchaka@gmail.com>
parents: 82919
diff changeset
81 .. function:: pformat(object, indent=1, width=80, depth=None, *, compact=False)
42604
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
82
85921
ae0306c8f7a3 Issue #19132: The pprint module now supports compact mode.
Serhiy Storchaka <storchaka@gmail.com>
parents: 82919
diff changeset
83 Return the formatted representation of *object* as a string. *indent*,
ae0306c8f7a3 Issue #19132: The pprint module now supports compact mode.
Serhiy Storchaka <storchaka@gmail.com>
parents: 82919
diff changeset
84 *width*, *depth* and *compact* will be passed to the :class:`PrettyPrinter`
ae0306c8f7a3 Issue #19132: The pprint module now supports compact mode.
Serhiy Storchaka <storchaka@gmail.com>
parents: 82919
diff changeset
85 constructor as formatting parameters.
42604
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
86
85932
6e7b1aadea2f Issue #19132: Add versionchanged tags.
Serhiy Storchaka <storchaka@gmail.com>
parents: 85921
diff changeset
87 .. versionchanged:: 3.4
6e7b1aadea2f Issue #19132: Add versionchanged tags.
Serhiy Storchaka <storchaka@gmail.com>
parents: 85921
diff changeset
88 Added the *compact* parameter.
6e7b1aadea2f Issue #19132: Add versionchanged tags.
Serhiy Storchaka <storchaka@gmail.com>
parents: 85921
diff changeset
89
42604
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
90
85921
ae0306c8f7a3 Issue #19132: The pprint module now supports compact mode.
Serhiy Storchaka <storchaka@gmail.com>
parents: 82919
diff changeset
91 .. function:: pprint(object, stream=None, indent=1, width=80, depth=None, *, \
ae0306c8f7a3 Issue #19132: The pprint module now supports compact mode.
Serhiy Storchaka <storchaka@gmail.com>
parents: 82919
diff changeset
92 compact=False)
42604
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
93
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
94 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
95 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
96 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
97 inspecting values (you can even reassign ``print = pprint.pprint`` for use
85921
ae0306c8f7a3 Issue #19132: The pprint module now supports compact mode.
Serhiy Storchaka <storchaka@gmail.com>
parents: 82919
diff changeset
98 within a scope). *indent*, *width*, *depth* and *compact* will be passed
ae0306c8f7a3 Issue #19132: The pprint module now supports compact mode.
Serhiy Storchaka <storchaka@gmail.com>
parents: 82919
diff changeset
99 to the :class:`PrettyPrinter` constructor as formatting parameters.
42604
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
100
85932
6e7b1aadea2f Issue #19132: Add versionchanged tags.
Serhiy Storchaka <storchaka@gmail.com>
parents: 85921
diff changeset
101 .. versionchanged:: 3.4
6e7b1aadea2f Issue #19132: Add versionchanged tags.
Serhiy Storchaka <storchaka@gmail.com>
parents: 85921
diff changeset
102 Added the *compact* parameter.
6e7b1aadea2f Issue #19132: Add versionchanged tags.
Serhiy Storchaka <storchaka@gmail.com>
parents: 85921
diff changeset
103
44187
05da49eb12c1 Merged revisions 59333-59370 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43219
diff changeset
104 >>> import pprint
05da49eb12c1 Merged revisions 59333-59370 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43219
diff changeset
105 >>> stuff = ['spam', 'eggs', 'lumberjack', 'knights', 'ni']
42604
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
106 >>> stuff.insert(0, stuff)
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
107 >>> 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
108 [<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
109 '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
110 '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
111 '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
112 '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
113 'ni']
42604
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
114
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
115
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
116 .. function:: isreadable(object)
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
117
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
118 .. index:: builtin: eval
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
119
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
120 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
121 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
122 for recursive objects.
42604
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.isreadable(stuff)
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
125 False
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 .. function:: isrecursive(object)
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 Determine if *object* requires a recursive representation.
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
131
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
132
42604
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
133 One more support function is also defined:
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 .. function:: saferepr(object)
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
136
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
137 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
138 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
139 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
140 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
141
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
142 >>> 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
143 "[<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
144
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
145
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
146 .. _prettyprinter-objects:
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
147
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
148 PrettyPrinter Objects
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
149 ---------------------
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
150
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
151 :class:`PrettyPrinter` instances have the following methods:
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
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
154 .. method:: PrettyPrinter.pformat(object)
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
155
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
156 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
157 options passed to the :class:`PrettyPrinter` constructor.
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
158
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
159
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
160 .. method:: PrettyPrinter.pprint(object)
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
161
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
162 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
163 followed by a newline.
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
164
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
165 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
166 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
167 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
168 created.
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
169
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
170
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
171 .. method:: PrettyPrinter.isreadable(object)
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 .. index:: builtin: eval
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 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
176 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
177 ``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
178 :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
179 returns ``False``.
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
180
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
181
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
182 .. method:: PrettyPrinter.isrecursive(object)
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
183
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
184 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
185
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
186 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
187 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
188 :func:`saferepr` implementation.
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
189
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
190
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
191 .. method:: PrettyPrinter.format(object, context, maxlevels, level)
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
192
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
193 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
194 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
195 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
196 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
197 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
198 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
199 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
200 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
201 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
202 *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
203 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
204 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
205 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
206
05da49eb12c1 Merged revisions 59333-59370 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43219
diff changeset
207
05da49eb12c1 Merged revisions 59333-59370 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43219
diff changeset
208 .. _pprint-example:
05da49eb12c1 Merged revisions 59333-59370 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43219
diff changeset
209
70106
ab16d8d4f75d pprint usage example rethought.
Łukasz Langa <lukasz@langa.pl>
parents: 55580
diff changeset
210 Example
ab16d8d4f75d pprint usage example rethought.
Łukasz Langa <lukasz@langa.pl>
parents: 55580
diff changeset
211 -------
44187
05da49eb12c1 Merged revisions 59333-59370 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43219
diff changeset
212
70106
ab16d8d4f75d pprint usage example rethought.
Łukasz Langa <lukasz@langa.pl>
parents: 55580
diff changeset
213 To demonstrate several uses of the :func:`pprint` function and its parameters,
82919
5a2296093645 Issue #17150: pprint now uses line continuations to wrap long string literals.
Antoine Pitrou <solipsis@pitrou.net>
parents: 70496
diff changeset
214 let's fetch information about a project from `PyPI <https://pypi.python.org>`_::
44187
05da49eb12c1 Merged revisions 59333-59370 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43219
diff changeset
215
70106
ab16d8d4f75d pprint usage example rethought.
Łukasz Langa <lukasz@langa.pl>
parents: 55580
diff changeset
216 >>> import json
44187
05da49eb12c1 Merged revisions 59333-59370 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43219
diff changeset
217 >>> import pprint
70106
ab16d8d4f75d pprint usage example rethought.
Łukasz Langa <lukasz@langa.pl>
parents: 55580
diff changeset
218 >>> from urllib.request import urlopen
82919
5a2296093645 Issue #17150: pprint now uses line continuations to wrap long string literals.
Antoine Pitrou <solipsis@pitrou.net>
parents: 70496
diff changeset
219 >>> with urlopen('http://pypi.python.org/pypi/Twisted/json') as url:
70106
ab16d8d4f75d pprint usage example rethought.
Łukasz Langa <lukasz@langa.pl>
parents: 55580
diff changeset
220 ... http_info = url.info()
ab16d8d4f75d pprint usage example rethought.
Łukasz Langa <lukasz@langa.pl>
parents: 55580
diff changeset
221 ... 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
222 >>> project_info = json.loads(raw_data)
70106
ab16d8d4f75d pprint usage example rethought.
Łukasz Langa <lukasz@langa.pl>
parents: 55580
diff changeset
223
ab16d8d4f75d pprint usage example rethought.
Łukasz Langa <lukasz@langa.pl>
parents: 55580
diff changeset
224 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
225
82919
5a2296093645 Issue #17150: pprint now uses line continuations to wrap long string literals.
Antoine Pitrou <solipsis@pitrou.net>
parents: 70496
diff changeset
226 >>> pprint.pprint(project_info)
5a2296093645 Issue #17150: pprint now uses line continuations to wrap long string literals.
Antoine Pitrou <solipsis@pitrou.net>
parents: 70496
diff changeset
227 {'info': {'_pypi_hidden': False,
5a2296093645 Issue #17150: pprint now uses line continuations to wrap long string literals.
Antoine Pitrou <solipsis@pitrou.net>
parents: 70496
diff changeset
228 '_pypi_ordering': 125,
5a2296093645 Issue #17150: pprint now uses line continuations to wrap long string literals.
Antoine Pitrou <solipsis@pitrou.net>
parents: 70496
diff changeset
229 'author': 'Glyph Lefkowitz',
5a2296093645 Issue #17150: pprint now uses line continuations to wrap long string literals.
Antoine Pitrou <solipsis@pitrou.net>
parents: 70496
diff changeset
230 'author_email': 'glyph@twistedmatrix.com',
5a2296093645 Issue #17150: pprint now uses line continuations to wrap long string literals.
Antoine Pitrou <solipsis@pitrou.net>
parents: 70496
diff changeset
231 'bugtrack_url': '',
5a2296093645 Issue #17150: pprint now uses line continuations to wrap long string literals.
Antoine Pitrou <solipsis@pitrou.net>
parents: 70496
diff changeset
232 'cheesecake_code_kwalitee_id': None,
5a2296093645 Issue #17150: pprint now uses line continuations to wrap long string literals.
Antoine Pitrou <solipsis@pitrou.net>
parents: 70496
diff changeset
233 'cheesecake_documentation_id': None,
5a2296093645 Issue #17150: pprint now uses line continuations to wrap long string literals.
Antoine Pitrou <solipsis@pitrou.net>
parents: 70496
diff changeset
234 'cheesecake_installability_id': None,
5a2296093645 Issue #17150: pprint now uses line continuations to wrap long string literals.
Antoine Pitrou <solipsis@pitrou.net>
parents: 70496
diff changeset
235 'classifiers': ['Programming Language :: Python :: 2.6',
5a2296093645 Issue #17150: pprint now uses line continuations to wrap long string literals.
Antoine Pitrou <solipsis@pitrou.net>
parents: 70496
diff changeset
236 'Programming Language :: Python :: 2.7',
5a2296093645 Issue #17150: pprint now uses line continuations to wrap long string literals.
Antoine Pitrou <solipsis@pitrou.net>
parents: 70496
diff changeset
237 'Programming Language :: Python :: 2 :: Only'],
5a2296093645 Issue #17150: pprint now uses line continuations to wrap long string literals.
Antoine Pitrou <solipsis@pitrou.net>
parents: 70496
diff changeset
238 'description': 'An extensible framework for Python programming, '
5a2296093645 Issue #17150: pprint now uses line continuations to wrap long string literals.
Antoine Pitrou <solipsis@pitrou.net>
parents: 70496
diff changeset
239 'with special focus\r\n'
5a2296093645 Issue #17150: pprint now uses line continuations to wrap long string literals.
Antoine Pitrou <solipsis@pitrou.net>
parents: 70496
diff changeset
240 'on event-based network programming and '
5a2296093645 Issue #17150: pprint now uses line continuations to wrap long string literals.
Antoine Pitrou <solipsis@pitrou.net>
parents: 70496
diff changeset
241 'multiprotocol integration.',
5a2296093645 Issue #17150: pprint now uses line continuations to wrap long string literals.
Antoine Pitrou <solipsis@pitrou.net>
parents: 70496
diff changeset
242 'docs_url': '',
5a2296093645 Issue #17150: pprint now uses line continuations to wrap long string literals.
Antoine Pitrou <solipsis@pitrou.net>
parents: 70496
diff changeset
243 'download_url': 'UNKNOWN',
5a2296093645 Issue #17150: pprint now uses line continuations to wrap long string literals.
Antoine Pitrou <solipsis@pitrou.net>
parents: 70496
diff changeset
244 'home_page': 'http://twistedmatrix.com/',
5a2296093645 Issue #17150: pprint now uses line continuations to wrap long string literals.
Antoine Pitrou <solipsis@pitrou.net>
parents: 70496
diff changeset
245 'keywords': '',
5a2296093645 Issue #17150: pprint now uses line continuations to wrap long string literals.
Antoine Pitrou <solipsis@pitrou.net>
parents: 70496
diff changeset
246 'license': 'MIT',
5a2296093645 Issue #17150: pprint now uses line continuations to wrap long string literals.
Antoine Pitrou <solipsis@pitrou.net>
parents: 70496
diff changeset
247 'maintainer': '',
5a2296093645 Issue #17150: pprint now uses line continuations to wrap long string literals.
Antoine Pitrou <solipsis@pitrou.net>
parents: 70496
diff changeset
248 'maintainer_email': '',
5a2296093645 Issue #17150: pprint now uses line continuations to wrap long string literals.
Antoine Pitrou <solipsis@pitrou.net>
parents: 70496
diff changeset
249 'name': 'Twisted',
5a2296093645 Issue #17150: pprint now uses line continuations to wrap long string literals.
Antoine Pitrou <solipsis@pitrou.net>
parents: 70496
diff changeset
250 'package_url': 'http://pypi.python.org/pypi/Twisted',
5a2296093645 Issue #17150: pprint now uses line continuations to wrap long string literals.
Antoine Pitrou <solipsis@pitrou.net>
parents: 70496
diff changeset
251 'platform': 'UNKNOWN',
5a2296093645 Issue #17150: pprint now uses line continuations to wrap long string literals.
Antoine Pitrou <solipsis@pitrou.net>
parents: 70496
diff changeset
252 'release_url': 'http://pypi.python.org/pypi/Twisted/12.3.0',
5a2296093645 Issue #17150: pprint now uses line continuations to wrap long string literals.
Antoine Pitrou <solipsis@pitrou.net>
parents: 70496
diff changeset
253 'requires_python': None,
5a2296093645 Issue #17150: pprint now uses line continuations to wrap long string literals.
Antoine Pitrou <solipsis@pitrou.net>
parents: 70496
diff changeset
254 'stable_version': None,
5a2296093645 Issue #17150: pprint now uses line continuations to wrap long string literals.
Antoine Pitrou <solipsis@pitrou.net>
parents: 70496
diff changeset
255 'summary': 'An asynchronous networking framework written in Python',
5a2296093645 Issue #17150: pprint now uses line continuations to wrap long string literals.
Antoine Pitrou <solipsis@pitrou.net>
parents: 70496
diff changeset
256 'version': '12.3.0'},
5a2296093645 Issue #17150: pprint now uses line continuations to wrap long string literals.
Antoine Pitrou <solipsis@pitrou.net>
parents: 70496
diff changeset
257 'urls': [{'comment_text': '',
5a2296093645 Issue #17150: pprint now uses line continuations to wrap long string literals.
Antoine Pitrou <solipsis@pitrou.net>
parents: 70496
diff changeset
258 'downloads': 71844,
5a2296093645 Issue #17150: pprint now uses line continuations to wrap long string literals.
Antoine Pitrou <solipsis@pitrou.net>
parents: 70496
diff changeset
259 'filename': 'Twisted-12.3.0.tar.bz2',
5a2296093645 Issue #17150: pprint now uses line continuations to wrap long string literals.
Antoine Pitrou <solipsis@pitrou.net>
parents: 70496
diff changeset
260 'has_sig': False,
5a2296093645 Issue #17150: pprint now uses line continuations to wrap long string literals.
Antoine Pitrou <solipsis@pitrou.net>
parents: 70496
diff changeset
261 'md5_digest': '6e289825f3bf5591cfd670874cc0862d',
5a2296093645 Issue #17150: pprint now uses line continuations to wrap long string literals.
Antoine Pitrou <solipsis@pitrou.net>
parents: 70496
diff changeset
262 'packagetype': 'sdist',
5a2296093645 Issue #17150: pprint now uses line continuations to wrap long string literals.
Antoine Pitrou <solipsis@pitrou.net>
parents: 70496
diff changeset
263 'python_version': 'source',
5a2296093645 Issue #17150: pprint now uses line continuations to wrap long string literals.
Antoine Pitrou <solipsis@pitrou.net>
parents: 70496
diff changeset
264 'size': 2615733,
5a2296093645 Issue #17150: pprint now uses line continuations to wrap long string literals.
Antoine Pitrou <solipsis@pitrou.net>
parents: 70496
diff changeset
265 'upload_time': '2012-12-26T12:47:03',
5a2296093645 Issue #17150: pprint now uses line continuations to wrap long string literals.
Antoine Pitrou <solipsis@pitrou.net>
parents: 70496
diff changeset
266 'url': 'https://pypi.python.org/packages/source/T/Twisted/Twisted-12.3.0.tar.bz2'},
5a2296093645 Issue #17150: pprint now uses line continuations to wrap long string literals.
Antoine Pitrou <solipsis@pitrou.net>
parents: 70496
diff changeset
267 {'comment_text': '',
5a2296093645 Issue #17150: pprint now uses line continuations to wrap long string literals.
Antoine Pitrou <solipsis@pitrou.net>
parents: 70496
diff changeset
268 'downloads': 5224,
5a2296093645 Issue #17150: pprint now uses line continuations to wrap long string literals.
Antoine Pitrou <solipsis@pitrou.net>
parents: 70496
diff changeset
269 'filename': 'Twisted-12.3.0.win32-py2.7.msi',
5a2296093645 Issue #17150: pprint now uses line continuations to wrap long string literals.
Antoine Pitrou <solipsis@pitrou.net>
parents: 70496
diff changeset
270 'has_sig': False,
5a2296093645 Issue #17150: pprint now uses line continuations to wrap long string literals.
Antoine Pitrou <solipsis@pitrou.net>
parents: 70496
diff changeset
271 'md5_digest': '6b778f5201b622a5519a2aca1a2fe512',
5a2296093645 Issue #17150: pprint now uses line continuations to wrap long string literals.
Antoine Pitrou <solipsis@pitrou.net>
parents: 70496
diff changeset
272 'packagetype': 'bdist_msi',
5a2296093645 Issue #17150: pprint now uses line continuations to wrap long string literals.
Antoine Pitrou <solipsis@pitrou.net>
parents: 70496
diff changeset
273 'python_version': '2.7',
5a2296093645 Issue #17150: pprint now uses line continuations to wrap long string literals.
Antoine Pitrou <solipsis@pitrou.net>
parents: 70496
diff changeset
274 'size': 2916352,
5a2296093645 Issue #17150: pprint now uses line continuations to wrap long string literals.
Antoine Pitrou <solipsis@pitrou.net>
parents: 70496
diff changeset
275 'upload_time': '2012-12-26T12:48:15',
5a2296093645 Issue #17150: pprint now uses line continuations to wrap long string literals.
Antoine Pitrou <solipsis@pitrou.net>
parents: 70496
diff changeset
276 'url': 'https://pypi.python.org/packages/2.7/T/Twisted/Twisted-12.3.0.win32-py2.7.msi'}]}
70106
ab16d8d4f75d pprint usage example rethought.
Łukasz Langa <lukasz@langa.pl>
parents: 55580
diff changeset
277
ab16d8d4f75d pprint usage example rethought.
Łukasz Langa <lukasz@langa.pl>
parents: 55580
diff changeset
278 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
279 contents)::
ab16d8d4f75d pprint usage example rethought.
Łukasz Langa <lukasz@langa.pl>
parents: 55580
diff changeset
280
82919
5a2296093645 Issue #17150: pprint now uses line continuations to wrap long string literals.
Antoine Pitrou <solipsis@pitrou.net>
parents: 70496
diff changeset
281 >>> pprint.pprint(project_info, depth=2)
5a2296093645 Issue #17150: pprint now uses line continuations to wrap long string literals.
Antoine Pitrou <solipsis@pitrou.net>
parents: 70496
diff changeset
282 {'info': {'_pypi_hidden': False,
5a2296093645 Issue #17150: pprint now uses line continuations to wrap long string literals.
Antoine Pitrou <solipsis@pitrou.net>
parents: 70496
diff changeset
283 '_pypi_ordering': 125,
5a2296093645 Issue #17150: pprint now uses line continuations to wrap long string literals.
Antoine Pitrou <solipsis@pitrou.net>
parents: 70496
diff changeset
284 'author': 'Glyph Lefkowitz',
5a2296093645 Issue #17150: pprint now uses line continuations to wrap long string literals.
Antoine Pitrou <solipsis@pitrou.net>
parents: 70496
diff changeset
285 'author_email': 'glyph@twistedmatrix.com',
5a2296093645 Issue #17150: pprint now uses line continuations to wrap long string literals.
Antoine Pitrou <solipsis@pitrou.net>
parents: 70496
diff changeset
286 'bugtrack_url': '',
5a2296093645 Issue #17150: pprint now uses line continuations to wrap long string literals.
Antoine Pitrou <solipsis@pitrou.net>
parents: 70496
diff changeset
287 'cheesecake_code_kwalitee_id': None,
5a2296093645 Issue #17150: pprint now uses line continuations to wrap long string literals.
Antoine Pitrou <solipsis@pitrou.net>
parents: 70496
diff changeset
288 'cheesecake_documentation_id': None,
5a2296093645 Issue #17150: pprint now uses line continuations to wrap long string literals.
Antoine Pitrou <solipsis@pitrou.net>
parents: 70496
diff changeset
289 'cheesecake_installability_id': None,
5a2296093645 Issue #17150: pprint now uses line continuations to wrap long string literals.
Antoine Pitrou <solipsis@pitrou.net>
parents: 70496
diff changeset
290 'classifiers': [...],
5a2296093645 Issue #17150: pprint now uses line continuations to wrap long string literals.
Antoine Pitrou <solipsis@pitrou.net>
parents: 70496
diff changeset
291 'description': 'An extensible framework for Python programming, '
5a2296093645 Issue #17150: pprint now uses line continuations to wrap long string literals.
Antoine Pitrou <solipsis@pitrou.net>
parents: 70496
diff changeset
292 'with special focus\r\n'
5a2296093645 Issue #17150: pprint now uses line continuations to wrap long string literals.
Antoine Pitrou <solipsis@pitrou.net>
parents: 70496
diff changeset
293 'on event-based network programming and '
5a2296093645 Issue #17150: pprint now uses line continuations to wrap long string literals.
Antoine Pitrou <solipsis@pitrou.net>
parents: 70496
diff changeset
294 'multiprotocol integration.',
5a2296093645 Issue #17150: pprint now uses line continuations to wrap long string literals.
Antoine Pitrou <solipsis@pitrou.net>
parents: 70496
diff changeset
295 'docs_url': '',
5a2296093645 Issue #17150: pprint now uses line continuations to wrap long string literals.
Antoine Pitrou <solipsis@pitrou.net>
parents: 70496
diff changeset
296 'download_url': 'UNKNOWN',
5a2296093645 Issue #17150: pprint now uses line continuations to wrap long string literals.
Antoine Pitrou <solipsis@pitrou.net>
parents: 70496
diff changeset
297 'home_page': 'http://twistedmatrix.com/',
5a2296093645 Issue #17150: pprint now uses line continuations to wrap long string literals.
Antoine Pitrou <solipsis@pitrou.net>
parents: 70496
diff changeset
298 'keywords': '',
5a2296093645 Issue #17150: pprint now uses line continuations to wrap long string literals.
Antoine Pitrou <solipsis@pitrou.net>
parents: 70496
diff changeset
299 'license': 'MIT',
5a2296093645 Issue #17150: pprint now uses line continuations to wrap long string literals.
Antoine Pitrou <solipsis@pitrou.net>
parents: 70496
diff changeset
300 'maintainer': '',
5a2296093645 Issue #17150: pprint now uses line continuations to wrap long string literals.
Antoine Pitrou <solipsis@pitrou.net>
parents: 70496
diff changeset
301 'maintainer_email': '',
5a2296093645 Issue #17150: pprint now uses line continuations to wrap long string literals.
Antoine Pitrou <solipsis@pitrou.net>
parents: 70496
diff changeset
302 'name': 'Twisted',
5a2296093645 Issue #17150: pprint now uses line continuations to wrap long string literals.
Antoine Pitrou <solipsis@pitrou.net>
parents: 70496
diff changeset
303 'package_url': 'http://pypi.python.org/pypi/Twisted',
5a2296093645 Issue #17150: pprint now uses line continuations to wrap long string literals.
Antoine Pitrou <solipsis@pitrou.net>
parents: 70496
diff changeset
304 'platform': 'UNKNOWN',
5a2296093645 Issue #17150: pprint now uses line continuations to wrap long string literals.
Antoine Pitrou <solipsis@pitrou.net>
parents: 70496
diff changeset
305 'release_url': 'http://pypi.python.org/pypi/Twisted/12.3.0',
5a2296093645 Issue #17150: pprint now uses line continuations to wrap long string literals.
Antoine Pitrou <solipsis@pitrou.net>
parents: 70496
diff changeset
306 'requires_python': None,
5a2296093645 Issue #17150: pprint now uses line continuations to wrap long string literals.
Antoine Pitrou <solipsis@pitrou.net>
parents: 70496
diff changeset
307 'stable_version': None,
5a2296093645 Issue #17150: pprint now uses line continuations to wrap long string literals.
Antoine Pitrou <solipsis@pitrou.net>
parents: 70496
diff changeset
308 'summary': 'An asynchronous networking framework written in Python',
5a2296093645 Issue #17150: pprint now uses line continuations to wrap long string literals.
Antoine Pitrou <solipsis@pitrou.net>
parents: 70496
diff changeset
309 'version': '12.3.0'},
5a2296093645 Issue #17150: pprint now uses line continuations to wrap long string literals.
Antoine Pitrou <solipsis@pitrou.net>
parents: 70496
diff changeset
310 'urls': [{...}, {...}]}
5a2296093645 Issue #17150: pprint now uses line continuations to wrap long string literals.
Antoine Pitrou <solipsis@pitrou.net>
parents: 70496
diff changeset
311
5a2296093645 Issue #17150: pprint now uses line continuations to wrap long string literals.
Antoine Pitrou <solipsis@pitrou.net>
parents: 70496
diff changeset
312 Additionally, maximum character *width* can be suggested. If a long object
5a2296093645 Issue #17150: pprint now uses line continuations to wrap long string literals.
Antoine Pitrou <solipsis@pitrou.net>
parents: 70496
diff changeset
313 cannot be split, the specified width will be exceeded::
70106
ab16d8d4f75d pprint usage example rethought.
Łukasz Langa <lukasz@langa.pl>
parents: 55580
diff changeset
314
82919
5a2296093645 Issue #17150: pprint now uses line continuations to wrap long string literals.
Antoine Pitrou <solipsis@pitrou.net>
parents: 70496
diff changeset
315 >>> pprint.pprint(project_info, depth=2, width=50)
5a2296093645 Issue #17150: pprint now uses line continuations to wrap long string literals.
Antoine Pitrou <solipsis@pitrou.net>
parents: 70496
diff changeset
316 {'info': {'_pypi_hidden': False,
5a2296093645 Issue #17150: pprint now uses line continuations to wrap long string literals.
Antoine Pitrou <solipsis@pitrou.net>
parents: 70496
diff changeset
317 '_pypi_ordering': 125,
5a2296093645 Issue #17150: pprint now uses line continuations to wrap long string literals.
Antoine Pitrou <solipsis@pitrou.net>
parents: 70496
diff changeset
318 'author': 'Glyph Lefkowitz',
5a2296093645 Issue #17150: pprint now uses line continuations to wrap long string literals.
Antoine Pitrou <solipsis@pitrou.net>
parents: 70496
diff changeset
319 'author_email': 'glyph@twistedmatrix.com',
5a2296093645 Issue #17150: pprint now uses line continuations to wrap long string literals.
Antoine Pitrou <solipsis@pitrou.net>
parents: 70496
diff changeset
320 'bugtrack_url': '',
5a2296093645 Issue #17150: pprint now uses line continuations to wrap long string literals.
Antoine Pitrou <solipsis@pitrou.net>
parents: 70496
diff changeset
321 'cheesecake_code_kwalitee_id': None,
5a2296093645 Issue #17150: pprint now uses line continuations to wrap long string literals.
Antoine Pitrou <solipsis@pitrou.net>
parents: 70496
diff changeset
322 'cheesecake_documentation_id': None,
5a2296093645 Issue #17150: pprint now uses line continuations to wrap long string literals.
Antoine Pitrou <solipsis@pitrou.net>
parents: 70496
diff changeset
323 'cheesecake_installability_id': None,
5a2296093645 Issue #17150: pprint now uses line continuations to wrap long string literals.
Antoine Pitrou <solipsis@pitrou.net>
parents: 70496
diff changeset
324 'classifiers': [...],
5a2296093645 Issue #17150: pprint now uses line continuations to wrap long string literals.
Antoine Pitrou <solipsis@pitrou.net>
parents: 70496
diff changeset
325 'description': 'An extensible '
5a2296093645 Issue #17150: pprint now uses line continuations to wrap long string literals.
Antoine Pitrou <solipsis@pitrou.net>
parents: 70496
diff changeset
326 'framework for '
5a2296093645 Issue #17150: pprint now uses line continuations to wrap long string literals.
Antoine Pitrou <solipsis@pitrou.net>
parents: 70496
diff changeset
327 'Python programming, '
5a2296093645 Issue #17150: pprint now uses line continuations to wrap long string literals.
Antoine Pitrou <solipsis@pitrou.net>
parents: 70496
diff changeset
328 'with special '
5a2296093645 Issue #17150: pprint now uses line continuations to wrap long string literals.
Antoine Pitrou <solipsis@pitrou.net>
parents: 70496
diff changeset
329 'focus\r\n'
5a2296093645 Issue #17150: pprint now uses line continuations to wrap long string literals.
Antoine Pitrou <solipsis@pitrou.net>
parents: 70496
diff changeset
330 'on event-based '
5a2296093645 Issue #17150: pprint now uses line continuations to wrap long string literals.
Antoine Pitrou <solipsis@pitrou.net>
parents: 70496
diff changeset
331 'network programming '
5a2296093645 Issue #17150: pprint now uses line continuations to wrap long string literals.
Antoine Pitrou <solipsis@pitrou.net>
parents: 70496
diff changeset
332 'and multiprotocol '
5a2296093645 Issue #17150: pprint now uses line continuations to wrap long string literals.
Antoine Pitrou <solipsis@pitrou.net>
parents: 70496
diff changeset
333 'integration.',
5a2296093645 Issue #17150: pprint now uses line continuations to wrap long string literals.
Antoine Pitrou <solipsis@pitrou.net>
parents: 70496
diff changeset
334 'docs_url': '',
5a2296093645 Issue #17150: pprint now uses line continuations to wrap long string literals.
Antoine Pitrou <solipsis@pitrou.net>
parents: 70496
diff changeset
335 'download_url': 'UNKNOWN',
5a2296093645 Issue #17150: pprint now uses line continuations to wrap long string literals.
Antoine Pitrou <solipsis@pitrou.net>
parents: 70496
diff changeset
336 'home_page': 'http://twistedmatrix.com/',
5a2296093645 Issue #17150: pprint now uses line continuations to wrap long string literals.
Antoine Pitrou <solipsis@pitrou.net>
parents: 70496
diff changeset
337 'keywords': '',
5a2296093645 Issue #17150: pprint now uses line continuations to wrap long string literals.
Antoine Pitrou <solipsis@pitrou.net>
parents: 70496
diff changeset
338 'license': 'MIT',
5a2296093645 Issue #17150: pprint now uses line continuations to wrap long string literals.
Antoine Pitrou <solipsis@pitrou.net>
parents: 70496
diff changeset
339 'maintainer': '',
5a2296093645 Issue #17150: pprint now uses line continuations to wrap long string literals.
Antoine Pitrou <solipsis@pitrou.net>
parents: 70496
diff changeset
340 'maintainer_email': '',
5a2296093645 Issue #17150: pprint now uses line continuations to wrap long string literals.
Antoine Pitrou <solipsis@pitrou.net>
parents: 70496
diff changeset
341 'name': 'Twisted',
5a2296093645 Issue #17150: pprint now uses line continuations to wrap long string literals.
Antoine Pitrou <solipsis@pitrou.net>
parents: 70496
diff changeset
342 'package_url': 'http://pypi.python.org/pypi/Twisted',
5a2296093645 Issue #17150: pprint now uses line continuations to wrap long string literals.
Antoine Pitrou <solipsis@pitrou.net>
parents: 70496
diff changeset
343 'platform': 'UNKNOWN',
5a2296093645 Issue #17150: pprint now uses line continuations to wrap long string literals.
Antoine Pitrou <solipsis@pitrou.net>
parents: 70496
diff changeset
344 'release_url': 'http://pypi.python.org/pypi/Twisted/12.3.0',
5a2296093645 Issue #17150: pprint now uses line continuations to wrap long string literals.
Antoine Pitrou <solipsis@pitrou.net>
parents: 70496
diff changeset
345 'requires_python': None,
5a2296093645 Issue #17150: pprint now uses line continuations to wrap long string literals.
Antoine Pitrou <solipsis@pitrou.net>
parents: 70496
diff changeset
346 'stable_version': None,
5a2296093645 Issue #17150: pprint now uses line continuations to wrap long string literals.
Antoine Pitrou <solipsis@pitrou.net>
parents: 70496
diff changeset
347 'summary': 'An asynchronous '
5a2296093645 Issue #17150: pprint now uses line continuations to wrap long string literals.
Antoine Pitrou <solipsis@pitrou.net>
parents: 70496
diff changeset
348 'networking framework '
5a2296093645 Issue #17150: pprint now uses line continuations to wrap long string literals.
Antoine Pitrou <solipsis@pitrou.net>
parents: 70496
diff changeset
349 'written in Python',
5a2296093645 Issue #17150: pprint now uses line continuations to wrap long string literals.
Antoine Pitrou <solipsis@pitrou.net>
parents: 70496
diff changeset
350 'version': '12.3.0'},
5a2296093645 Issue #17150: pprint now uses line continuations to wrap long string literals.
Antoine Pitrou <solipsis@pitrou.net>
parents: 70496
diff changeset
351 'urls': [{...}, {...}]}