annotate Doc/lib/libpprint.tex @ 24042:63fbbed10714 legacy-trunk

Simplify HTTPSConnection constructor. See discussion in SF bug 458463.
author Jeremy Hylton <jeremy@alum.mit.edu>
date Fri, 28 Jun 2002 23:38:14 +0000
parents d26d8575ac62
children f967589df751
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8918
acfffe14628e New section header style.
Fred Drake <fdrake@acm.org>
parents: 8716
diff changeset
1 \section{\module{pprint} ---
15142
563dee598d3a Fixed lots of small nits caught by Ka-Ping Yee <ping@lfw.org>.
Fred Drake <fdrake@acm.org>
parents: 10239
diff changeset
2 Data pretty printer}
10239
c1befdbd64e5 Record module & documentation author.
Fred Drake <fdrake@acm.org>
parents: 8918
diff changeset
3
8716
760dcf197048 Adjusted to use the new module synopsis support macros.
Fred Drake <fdrake@acm.org>
parents: 7877
diff changeset
4 \declaremodule{standard}{pprint}
760dcf197048 Adjusted to use the new module synopsis support macros.
Fred Drake <fdrake@acm.org>
parents: 7877
diff changeset
5 \modulesynopsis{Data pretty printer.}
10239
c1befdbd64e5 Record module & documentation author.
Fred Drake <fdrake@acm.org>
parents: 8918
diff changeset
6 \moduleauthor{Fred L. Drake, Jr.}{fdrake@acm.org}
c1befdbd64e5 Record module & documentation author.
Fred Drake <fdrake@acm.org>
parents: 8918
diff changeset
7 \sectionauthor{Fred L. Drake, Jr.}{fdrake@acm.org}
8716
760dcf197048 Adjusted to use the new module synopsis support macros.
Fred Drake <fdrake@acm.org>
parents: 7877
diff changeset
8
5836
3a798677506c Documentation for the pprint module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
9
7424
11e9337cda3d Added \label{}s for logical addressing.
Fred Drake <fdrake@acm.org>
parents: 7277
diff changeset
10 The \module{pprint} module provides a capability to ``pretty-print''
5836
3a798677506c Documentation for the pprint module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
11 arbitrary Python data structures in a form which can be used as input
3a798677506c Documentation for the pprint module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
12 to the interpreter. If the formatted structures include objects which
3a798677506c Documentation for the pprint module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
13 are not fundamental Python types, the representation may not be
3a798677506c Documentation for the pprint module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
14 loadable. This may be the case if objects such as files, sockets,
3a798677506c Documentation for the pprint module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
15 classes, or instances are included, as well as many other builtin
3a798677506c Documentation for the pprint module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
16 objects which are not representable as Python constants.
3a798677506c Documentation for the pprint module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
17
3a798677506c Documentation for the pprint module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
18 The formatted representation keeps objects on a single line if it can,
5896
67022d28a65d A couple of grammatical nits.
Fred Drake <fdrake@acm.org>
parents: 5836
diff changeset
19 and breaks them onto multiple lines if they don't fit within the
7424
11e9337cda3d Added \label{}s for logical addressing.
Fred Drake <fdrake@acm.org>
parents: 7277
diff changeset
20 allowed width. Construct \class{PrettyPrinter} objects explicitly if
11e9337cda3d Added \label{}s for logical addressing.
Fred Drake <fdrake@acm.org>
parents: 7277
diff changeset
21 you need to adjust the width constraint.
5836
3a798677506c Documentation for the pprint module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
22
7424
11e9337cda3d Added \label{}s for logical addressing.
Fred Drake <fdrake@acm.org>
parents: 7277
diff changeset
23 The \module{pprint} module defines one class:
5836
3a798677506c Documentation for the pprint module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
24
3a798677506c Documentation for the pprint module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
25
5896
67022d28a65d A couple of grammatical nits.
Fred Drake <fdrake@acm.org>
parents: 5836
diff changeset
26 % First the implementation class:
5836
3a798677506c Documentation for the pprint module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
27
7424
11e9337cda3d Added \label{}s for logical addressing.
Fred Drake <fdrake@acm.org>
parents: 7277
diff changeset
28 \begin{classdesc}{PrettyPrinter}{...}
11e9337cda3d Added \label{}s for logical addressing.
Fred Drake <fdrake@acm.org>
parents: 7277
diff changeset
29 Construct a \class{PrettyPrinter} instance. This constructor
11e9337cda3d Added \label{}s for logical addressing.
Fred Drake <fdrake@acm.org>
parents: 7277
diff changeset
30 understands several keyword parameters. An output stream may be set
11e9337cda3d Added \label{}s for logical addressing.
Fred Drake <fdrake@acm.org>
parents: 7277
diff changeset
31 using the \var{stream} keyword; the only method used on the stream
11e9337cda3d Added \label{}s for logical addressing.
Fred Drake <fdrake@acm.org>
parents: 7277
diff changeset
32 object is the file protocol's \method{write()} method. If not
11e9337cda3d Added \label{}s for logical addressing.
Fred Drake <fdrake@acm.org>
parents: 7277
diff changeset
33 specified, the \class{PrettyPrinter} adopts \code{sys.stdout}. Three
11e9337cda3d Added \label{}s for logical addressing.
Fred Drake <fdrake@acm.org>
parents: 7277
diff changeset
34 additional parameters may be used to control the formatted
11e9337cda3d Added \label{}s for logical addressing.
Fred Drake <fdrake@acm.org>
parents: 7277
diff changeset
35 representation. The keywords are \var{indent}, \var{depth}, and
11e9337cda3d Added \label{}s for logical addressing.
Fred Drake <fdrake@acm.org>
parents: 7277
diff changeset
36 \var{width}. The amount of indentation added for each recursive level
11e9337cda3d Added \label{}s for logical addressing.
Fred Drake <fdrake@acm.org>
parents: 7277
diff changeset
37 is specified by \var{indent}; the default is one. Other values can
11e9337cda3d Added \label{}s for logical addressing.
Fred Drake <fdrake@acm.org>
parents: 7277
diff changeset
38 cause output to look a little odd, but can make nesting easier to
11e9337cda3d Added \label{}s for logical addressing.
Fred Drake <fdrake@acm.org>
parents: 7277
diff changeset
39 spot. The number of levels which may be printed is controlled by
11e9337cda3d Added \label{}s for logical addressing.
Fred Drake <fdrake@acm.org>
parents: 7277
diff changeset
40 \var{depth}; if the data structure being printed is too deep, the next
11e9337cda3d Added \label{}s for logical addressing.
Fred Drake <fdrake@acm.org>
parents: 7277
diff changeset
41 contained level is replaced by \samp{...}. By default, there is no
11e9337cda3d Added \label{}s for logical addressing.
Fred Drake <fdrake@acm.org>
parents: 7277
diff changeset
42 constraint on the depth of the objects being formatted. The desired
11e9337cda3d Added \label{}s for logical addressing.
Fred Drake <fdrake@acm.org>
parents: 7277
diff changeset
43 output width is constrained using the \var{width} parameter; the
11e9337cda3d Added \label{}s for logical addressing.
Fred Drake <fdrake@acm.org>
parents: 7277
diff changeset
44 default is eighty characters. If a structure cannot be formatted
11e9337cda3d Added \label{}s for logical addressing.
Fred Drake <fdrake@acm.org>
parents: 7277
diff changeset
45 within the constrained width, a best effort will be made.
5836
3a798677506c Documentation for the pprint module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
46
3a798677506c Documentation for the pprint module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
47 \begin{verbatim}
5896
67022d28a65d A couple of grammatical nits.
Fred Drake <fdrake@acm.org>
parents: 5836
diff changeset
48 >>> import pprint, sys
5836
3a798677506c Documentation for the pprint module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
49 >>> stuff = sys.path[:]
5896
67022d28a65d A couple of grammatical nits.
Fred Drake <fdrake@acm.org>
parents: 5836
diff changeset
50 >>> stuff.insert(0, stuff[:])
5836
3a798677506c Documentation for the pprint module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
51 >>> pp = pprint.PrettyPrinter(indent=4)
3a798677506c Documentation for the pprint module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
52 >>> pp.pprint(stuff)
3a798677506c Documentation for the pprint module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
53 [ [ '',
5896
67022d28a65d A couple of grammatical nits.
Fred Drake <fdrake@acm.org>
parents: 5836
diff changeset
54 '/usr/local/lib/python1.5',
67022d28a65d A couple of grammatical nits.
Fred Drake <fdrake@acm.org>
parents: 5836
diff changeset
55 '/usr/local/lib/python1.5/test',
67022d28a65d A couple of grammatical nits.
Fred Drake <fdrake@acm.org>
parents: 5836
diff changeset
56 '/usr/local/lib/python1.5/sunos5',
67022d28a65d A couple of grammatical nits.
Fred Drake <fdrake@acm.org>
parents: 5836
diff changeset
57 '/usr/local/lib/python1.5/sharedmodules',
67022d28a65d A couple of grammatical nits.
Fred Drake <fdrake@acm.org>
parents: 5836
diff changeset
58 '/usr/local/lib/python1.5/tkinter'],
5836
3a798677506c Documentation for the pprint module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
59 '',
5896
67022d28a65d A couple of grammatical nits.
Fred Drake <fdrake@acm.org>
parents: 5836
diff changeset
60 '/usr/local/lib/python1.5',
67022d28a65d A couple of grammatical nits.
Fred Drake <fdrake@acm.org>
parents: 5836
diff changeset
61 '/usr/local/lib/python1.5/test',
67022d28a65d A couple of grammatical nits.
Fred Drake <fdrake@acm.org>
parents: 5836
diff changeset
62 '/usr/local/lib/python1.5/sunos5',
67022d28a65d A couple of grammatical nits.
Fred Drake <fdrake@acm.org>
parents: 5836
diff changeset
63 '/usr/local/lib/python1.5/sharedmodules',
67022d28a65d A couple of grammatical nits.
Fred Drake <fdrake@acm.org>
parents: 5836
diff changeset
64 '/usr/local/lib/python1.5/tkinter']
5836
3a798677506c Documentation for the pprint module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
65 >>>
3a798677506c Documentation for the pprint module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
66 >>> import parser
3a798677506c Documentation for the pprint module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
67 >>> tup = parser.ast2tuple(
3a798677506c Documentation for the pprint module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
68 ... parser.suite(open('pprint.py').read()))[1][1][1]
3a798677506c Documentation for the pprint module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
69 >>> pp = pprint.PrettyPrinter(depth=6)
3a798677506c Documentation for the pprint module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
70 >>> pp.pprint(tup)
3a798677506c Documentation for the pprint module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
71 (266, (267, (307, (287, (288, (...))))))
3a798677506c Documentation for the pprint module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
72 \end{verbatim}
7424
11e9337cda3d Added \label{}s for logical addressing.
Fred Drake <fdrake@acm.org>
parents: 7277
diff changeset
73 \end{classdesc}
5896
67022d28a65d A couple of grammatical nits.
Fred Drake <fdrake@acm.org>
parents: 5836
diff changeset
74
67022d28a65d A couple of grammatical nits.
Fred Drake <fdrake@acm.org>
parents: 5836
diff changeset
75
67022d28a65d A couple of grammatical nits.
Fred Drake <fdrake@acm.org>
parents: 5836
diff changeset
76 % Now the derivative functions:
67022d28a65d A couple of grammatical nits.
Fred Drake <fdrake@acm.org>
parents: 5836
diff changeset
77
7424
11e9337cda3d Added \label{}s for logical addressing.
Fred Drake <fdrake@acm.org>
parents: 7277
diff changeset
78 The \class{PrettyPrinter} class supports several derivative functions:
5896
67022d28a65d A couple of grammatical nits.
Fred Drake <fdrake@acm.org>
parents: 5836
diff changeset
79
67022d28a65d A couple of grammatical nits.
Fred Drake <fdrake@acm.org>
parents: 5836
diff changeset
80 \begin{funcdesc}{pformat}{object}
67022d28a65d A couple of grammatical nits.
Fred Drake <fdrake@acm.org>
parents: 5836
diff changeset
81 Return the formatted representation of \var{object} as a string. The
67022d28a65d A couple of grammatical nits.
Fred Drake <fdrake@acm.org>
parents: 5836
diff changeset
82 default parameters for formatting are used.
67022d28a65d A couple of grammatical nits.
Fred Drake <fdrake@acm.org>
parents: 5836
diff changeset
83 \end{funcdesc}
67022d28a65d A couple of grammatical nits.
Fred Drake <fdrake@acm.org>
parents: 5836
diff changeset
84
67022d28a65d A couple of grammatical nits.
Fred Drake <fdrake@acm.org>
parents: 5836
diff changeset
85 \begin{funcdesc}{pprint}{object\optional{, stream}}
67022d28a65d A couple of grammatical nits.
Fred Drake <fdrake@acm.org>
parents: 5836
diff changeset
86 Prints the formatted representation of \var{object} on \var{stream},
67022d28a65d A couple of grammatical nits.
Fred Drake <fdrake@acm.org>
parents: 5836
diff changeset
87 followed by a newline. If \var{stream} is omitted, \code{sys.stdout}
67022d28a65d A couple of grammatical nits.
Fred Drake <fdrake@acm.org>
parents: 5836
diff changeset
88 is used. This may be used in the interactive interpreter instead of a
7424
11e9337cda3d Added \label{}s for logical addressing.
Fred Drake <fdrake@acm.org>
parents: 7277
diff changeset
89 \keyword{print} statement for inspecting values. The default
11e9337cda3d Added \label{}s for logical addressing.
Fred Drake <fdrake@acm.org>
parents: 7277
diff changeset
90 parameters for formatting are used.
5896
67022d28a65d A couple of grammatical nits.
Fred Drake <fdrake@acm.org>
parents: 5836
diff changeset
91
67022d28a65d A couple of grammatical nits.
Fred Drake <fdrake@acm.org>
parents: 5836
diff changeset
92 \begin{verbatim}
67022d28a65d A couple of grammatical nits.
Fred Drake <fdrake@acm.org>
parents: 5836
diff changeset
93 >>> stuff = sys.path[:]
67022d28a65d A couple of grammatical nits.
Fred Drake <fdrake@acm.org>
parents: 5836
diff changeset
94 >>> stuff.insert(0, stuff)
67022d28a65d A couple of grammatical nits.
Fred Drake <fdrake@acm.org>
parents: 5836
diff changeset
95 >>> pprint.pprint(stuff)
67022d28a65d A couple of grammatical nits.
Fred Drake <fdrake@acm.org>
parents: 5836
diff changeset
96 [<Recursion on list with id=869440>,
67022d28a65d A couple of grammatical nits.
Fred Drake <fdrake@acm.org>
parents: 5836
diff changeset
97 '',
67022d28a65d A couple of grammatical nits.
Fred Drake <fdrake@acm.org>
parents: 5836
diff changeset
98 '/usr/local/lib/python1.5',
67022d28a65d A couple of grammatical nits.
Fred Drake <fdrake@acm.org>
parents: 5836
diff changeset
99 '/usr/local/lib/python1.5/test',
67022d28a65d A couple of grammatical nits.
Fred Drake <fdrake@acm.org>
parents: 5836
diff changeset
100 '/usr/local/lib/python1.5/sunos5',
67022d28a65d A couple of grammatical nits.
Fred Drake <fdrake@acm.org>
parents: 5836
diff changeset
101 '/usr/local/lib/python1.5/sharedmodules',
67022d28a65d A couple of grammatical nits.
Fred Drake <fdrake@acm.org>
parents: 5836
diff changeset
102 '/usr/local/lib/python1.5/tkinter']
67022d28a65d A couple of grammatical nits.
Fred Drake <fdrake@acm.org>
parents: 5836
diff changeset
103 \end{verbatim}
67022d28a65d A couple of grammatical nits.
Fred Drake <fdrake@acm.org>
parents: 5836
diff changeset
104 \end{funcdesc}
67022d28a65d A couple of grammatical nits.
Fred Drake <fdrake@acm.org>
parents: 5836
diff changeset
105
67022d28a65d A couple of grammatical nits.
Fred Drake <fdrake@acm.org>
parents: 5836
diff changeset
106 \begin{funcdesc}{isreadable}{object}
67022d28a65d A couple of grammatical nits.
Fred Drake <fdrake@acm.org>
parents: 5836
diff changeset
107 Determine if the formatted representation of \var{object} is
67022d28a65d A couple of grammatical nits.
Fred Drake <fdrake@acm.org>
parents: 5836
diff changeset
108 ``readable,'' or can be used to reconstruct the value using
7829
e2fb25784530 Talk about some minor nits...
Fred Drake <fdrake@acm.org>
parents: 7768
diff changeset
109 \function{eval()}\bifuncindex{eval}. This always returns false for
7424
11e9337cda3d Added \label{}s for logical addressing.
Fred Drake <fdrake@acm.org>
parents: 7277
diff changeset
110 recursive objects.
5896
67022d28a65d A couple of grammatical nits.
Fred Drake <fdrake@acm.org>
parents: 5836
diff changeset
111
67022d28a65d A couple of grammatical nits.
Fred Drake <fdrake@acm.org>
parents: 5836
diff changeset
112 \begin{verbatim}
67022d28a65d A couple of grammatical nits.
Fred Drake <fdrake@acm.org>
parents: 5836
diff changeset
113 >>> pprint.isreadable(stuff)
67022d28a65d A couple of grammatical nits.
Fred Drake <fdrake@acm.org>
parents: 5836
diff changeset
114 0
67022d28a65d A couple of grammatical nits.
Fred Drake <fdrake@acm.org>
parents: 5836
diff changeset
115 \end{verbatim}
67022d28a65d A couple of grammatical nits.
Fred Drake <fdrake@acm.org>
parents: 5836
diff changeset
116 \end{funcdesc}
67022d28a65d A couple of grammatical nits.
Fred Drake <fdrake@acm.org>
parents: 5836
diff changeset
117
67022d28a65d A couple of grammatical nits.
Fred Drake <fdrake@acm.org>
parents: 5836
diff changeset
118 \begin{funcdesc}{isrecursive}{object}
67022d28a65d A couple of grammatical nits.
Fred Drake <fdrake@acm.org>
parents: 5836
diff changeset
119 Determine if \var{object} requires a recursive representation.
67022d28a65d A couple of grammatical nits.
Fred Drake <fdrake@acm.org>
parents: 5836
diff changeset
120 \end{funcdesc}
67022d28a65d A couple of grammatical nits.
Fred Drake <fdrake@acm.org>
parents: 5836
diff changeset
121
67022d28a65d A couple of grammatical nits.
Fred Drake <fdrake@acm.org>
parents: 5836
diff changeset
122
67022d28a65d A couple of grammatical nits.
Fred Drake <fdrake@acm.org>
parents: 5836
diff changeset
123 One more support function is also defined:
67022d28a65d A couple of grammatical nits.
Fred Drake <fdrake@acm.org>
parents: 5836
diff changeset
124
67022d28a65d A couple of grammatical nits.
Fred Drake <fdrake@acm.org>
parents: 5836
diff changeset
125 \begin{funcdesc}{saferepr}{object}
67022d28a65d A couple of grammatical nits.
Fred Drake <fdrake@acm.org>
parents: 5836
diff changeset
126 Return a string representation of \var{object}, protected against
67022d28a65d A couple of grammatical nits.
Fred Drake <fdrake@acm.org>
parents: 5836
diff changeset
127 recursive data structures. If the representation of \var{object}
67022d28a65d A couple of grammatical nits.
Fred Drake <fdrake@acm.org>
parents: 5836
diff changeset
128 exposes a recursive entry, the recursive reference will be represented
6901
adb300cbd566 Make the word "Module" in the section header start with an upper-case "M".
Fred Drake <fdrake@acm.org>
parents: 6647
diff changeset
129 as \samp{<Recursion on \var{typename} with id=\var{number}>}. The
5896
67022d28a65d A couple of grammatical nits.
Fred Drake <fdrake@acm.org>
parents: 5836
diff changeset
130 representation is not otherwise formatted.
7608
893a32095222 Small nits.
Fred Drake <fdrake@acm.org>
parents: 7424
diff changeset
131 \end{funcdesc}
5896
67022d28a65d A couple of grammatical nits.
Fred Drake <fdrake@acm.org>
parents: 5836
diff changeset
132
7608
893a32095222 Small nits.
Fred Drake <fdrake@acm.org>
parents: 7424
diff changeset
133 % This example is outside the {funcdesc} to keep it from running over
893a32095222 Small nits.
Fred Drake <fdrake@acm.org>
parents: 7424
diff changeset
134 % the right margin.
5896
67022d28a65d A couple of grammatical nits.
Fred Drake <fdrake@acm.org>
parents: 5836
diff changeset
135 \begin{verbatim}
67022d28a65d A couple of grammatical nits.
Fred Drake <fdrake@acm.org>
parents: 5836
diff changeset
136 >>> pprint.saferepr(stuff)
7829
e2fb25784530 Talk about some minor nits...
Fred Drake <fdrake@acm.org>
parents: 7768
diff changeset
137 "[<Recursion on list with id=682968>, '', '/usr/local/lib/python1.5', '/usr/loca
e2fb25784530 Talk about some minor nits...
Fred Drake <fdrake@acm.org>
parents: 7768
diff changeset
138 l/lib/python1.5/test', '/usr/local/lib/python1.5/sunos5', '/usr/local/lib/python
e2fb25784530 Talk about some minor nits...
Fred Drake <fdrake@acm.org>
parents: 7768
diff changeset
139 1.5/sharedmodules', '/usr/local/lib/python1.5/tkinter']"
5896
67022d28a65d A couple of grammatical nits.
Fred Drake <fdrake@acm.org>
parents: 5836
diff changeset
140 \end{verbatim}
5836
3a798677506c Documentation for the pprint module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
141
3a798677506c Documentation for the pprint module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
142
3a798677506c Documentation for the pprint module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
143 \subsection{PrettyPrinter Objects}
7424
11e9337cda3d Added \label{}s for logical addressing.
Fred Drake <fdrake@acm.org>
parents: 7277
diff changeset
144 \label{PrettyPrinter Objects}
5836
3a798677506c Documentation for the pprint module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
145
7608
893a32095222 Small nits.
Fred Drake <fdrake@acm.org>
parents: 7424
diff changeset
146 \class{PrettyPrinter} instances have the following methods:
5836
3a798677506c Documentation for the pprint module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
147
3a798677506c Documentation for the pprint module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
148
7768
8f177933c41f Use the new {methoddesc} and {memberdesc} environments as appropriate.
Fred Drake <fdrake@acm.org>
parents: 7608
diff changeset
149 \begin{methoddesc}{pformat}{object}
5836
3a798677506c Documentation for the pprint module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
150 Return the formatted representation of \var{object}. This takes into
7768
8f177933c41f Use the new {methoddesc} and {memberdesc} environments as appropriate.
Fred Drake <fdrake@acm.org>
parents: 7608
diff changeset
151 Account the options passed to the \class{PrettyPrinter} constructor.
8f177933c41f Use the new {methoddesc} and {memberdesc} environments as appropriate.
Fred Drake <fdrake@acm.org>
parents: 7608
diff changeset
152 \end{methoddesc}
5836
3a798677506c Documentation for the pprint module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
153
7768
8f177933c41f Use the new {methoddesc} and {memberdesc} environments as appropriate.
Fred Drake <fdrake@acm.org>
parents: 7608
diff changeset
154 \begin{methoddesc}{pprint}{object}
5836
3a798677506c Documentation for the pprint module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
155 Print the formatted representation of \var{object} on the configured
3a798677506c Documentation for the pprint module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
156 stream, followed by a newline.
7768
8f177933c41f Use the new {methoddesc} and {memberdesc} environments as appropriate.
Fred Drake <fdrake@acm.org>
parents: 7608
diff changeset
157 \end{methoddesc}
5836
3a798677506c Documentation for the pprint module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
158
3a798677506c Documentation for the pprint module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
159 The following methods provide the implementations for the
3a798677506c Documentation for the pprint module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
160 corresponding functions of the same names. Using these methods on an
7424
11e9337cda3d Added \label{}s for logical addressing.
Fred Drake <fdrake@acm.org>
parents: 7277
diff changeset
161 instance is slightly more efficient since new \class{PrettyPrinter}
11e9337cda3d Added \label{}s for logical addressing.
Fred Drake <fdrake@acm.org>
parents: 7277
diff changeset
162 objects don't need to be created.
5836
3a798677506c Documentation for the pprint module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
163
7768
8f177933c41f Use the new {methoddesc} and {memberdesc} environments as appropriate.
Fred Drake <fdrake@acm.org>
parents: 7608
diff changeset
164 \begin{methoddesc}{isreadable}{object}
5836
3a798677506c Documentation for the pprint module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
165 Determine if the formatted representation of the object is
3a798677506c Documentation for the pprint module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
166 ``readable,'' or can be used to reconstruct the value using
7424
11e9337cda3d Added \label{}s for logical addressing.
Fred Drake <fdrake@acm.org>
parents: 7277
diff changeset
167 \function{eval()}\bifuncindex{eval}. Note that this returns false for
11e9337cda3d Added \label{}s for logical addressing.
Fred Drake <fdrake@acm.org>
parents: 7277
diff changeset
168 recursive objects. If the \var{depth} parameter of the
11e9337cda3d Added \label{}s for logical addressing.
Fred Drake <fdrake@acm.org>
parents: 7277
diff changeset
169 \class{PrettyPrinter} is set and the object is deeper than allowed,
11e9337cda3d Added \label{}s for logical addressing.
Fred Drake <fdrake@acm.org>
parents: 7277
diff changeset
170 this returns false.
7768
8f177933c41f Use the new {methoddesc} and {memberdesc} environments as appropriate.
Fred Drake <fdrake@acm.org>
parents: 7608
diff changeset
171 \end{methoddesc}
5836
3a798677506c Documentation for the pprint module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
172
7768
8f177933c41f Use the new {methoddesc} and {memberdesc} environments as appropriate.
Fred Drake <fdrake@acm.org>
parents: 7608
diff changeset
173 \begin{methoddesc}{isrecursive}{object}
5836
3a798677506c Documentation for the pprint module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
174 Determine if the object requires a recursive representation.
7768
8f177933c41f Use the new {methoddesc} and {memberdesc} environments as appropriate.
Fred Drake <fdrake@acm.org>
parents: 7608
diff changeset
175 \end{methoddesc}
22766
d26d8575ac62 Add an experimental mechanism to support extending the pprint formatting.
Fred Drake <fdrake@acm.org>
parents: 15142
diff changeset
176
d26d8575ac62 Add an experimental mechanism to support extending the pprint formatting.
Fred Drake <fdrake@acm.org>
parents: 15142
diff changeset
177 This method is provided as a hook to allow subclasses to modify the
d26d8575ac62 Add an experimental mechanism to support extending the pprint formatting.
Fred Drake <fdrake@acm.org>
parents: 15142
diff changeset
178 way objects are converted to strings. The default implementation uses
d26d8575ac62 Add an experimental mechanism to support extending the pprint formatting.
Fred Drake <fdrake@acm.org>
parents: 15142
diff changeset
179 the internals of the \function{saferepr()} implementation.
d26d8575ac62 Add an experimental mechanism to support extending the pprint formatting.
Fred Drake <fdrake@acm.org>
parents: 15142
diff changeset
180
d26d8575ac62 Add an experimental mechanism to support extending the pprint formatting.
Fred Drake <fdrake@acm.org>
parents: 15142
diff changeset
181 \begin{methoddesc}{format}{object, context, maxlevels, level}
d26d8575ac62 Add an experimental mechanism to support extending the pprint formatting.
Fred Drake <fdrake@acm.org>
parents: 15142
diff changeset
182 Returns three values: the formatted version of \var{object} as a
d26d8575ac62 Add an experimental mechanism to support extending the pprint formatting.
Fred Drake <fdrake@acm.org>
parents: 15142
diff changeset
183 string, a flag indicating whether the result is readable, and a flag
d26d8575ac62 Add an experimental mechanism to support extending the pprint formatting.
Fred Drake <fdrake@acm.org>
parents: 15142
diff changeset
184 indicating whether recursion was detected. The first argument is the
d26d8575ac62 Add an experimental mechanism to support extending the pprint formatting.
Fred Drake <fdrake@acm.org>
parents: 15142
diff changeset
185 object to be presented. The second is a dictionary which contains the
d26d8575ac62 Add an experimental mechanism to support extending the pprint formatting.
Fred Drake <fdrake@acm.org>
parents: 15142
diff changeset
186 \function{id()} of objects that are part of the current presentation
d26d8575ac62 Add an experimental mechanism to support extending the pprint formatting.
Fred Drake <fdrake@acm.org>
parents: 15142
diff changeset
187 context (direct and indirect containers for \var{object} that are
d26d8575ac62 Add an experimental mechanism to support extending the pprint formatting.
Fred Drake <fdrake@acm.org>
parents: 15142
diff changeset
188 affecting the presentation) as the keys; if an object needs to be
d26d8575ac62 Add an experimental mechanism to support extending the pprint formatting.
Fred Drake <fdrake@acm.org>
parents: 15142
diff changeset
189 presented which is already represented in \var{context}, the third
d26d8575ac62 Add an experimental mechanism to support extending the pprint formatting.
Fred Drake <fdrake@acm.org>
parents: 15142
diff changeset
190 return value should be true. Recursive calls to the \method{format()}
d26d8575ac62 Add an experimental mechanism to support extending the pprint formatting.
Fred Drake <fdrake@acm.org>
parents: 15142
diff changeset
191 method should add additionaly entries for containers to this
d26d8575ac62 Add an experimental mechanism to support extending the pprint formatting.
Fred Drake <fdrake@acm.org>
parents: 15142
diff changeset
192 dictionary. The fourth argument, \var{maxlevels}, gives the requested
d26d8575ac62 Add an experimental mechanism to support extending the pprint formatting.
Fred Drake <fdrake@acm.org>
parents: 15142
diff changeset
193 limit to recursion; this will be \code{0} if there is no requested
d26d8575ac62 Add an experimental mechanism to support extending the pprint formatting.
Fred Drake <fdrake@acm.org>
parents: 15142
diff changeset
194 limit. This argument should be passed unmodified to recursive calls.
d26d8575ac62 Add an experimental mechanism to support extending the pprint formatting.
Fred Drake <fdrake@acm.org>
parents: 15142
diff changeset
195 The fourth argument, \var{level} gives the current level; recursive
d26d8575ac62 Add an experimental mechanism to support extending the pprint formatting.
Fred Drake <fdrake@acm.org>
parents: 15142
diff changeset
196 calls should be passed a value less than that of the current call.
d26d8575ac62 Add an experimental mechanism to support extending the pprint formatting.
Fred Drake <fdrake@acm.org>
parents: 15142
diff changeset
197 \versionadded{2.3}
d26d8575ac62 Add an experimental mechanism to support extending the pprint formatting.
Fred Drake <fdrake@acm.org>
parents: 15142
diff changeset
198 \end{methoddesc}