Commit | Line | Data |
---|---|---|
920dae64 AT |
1 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> |
2 | <html> | |
3 | <head> | |
4 | <link rel="STYLESHEET" href="lib.css" type='text/css' /> | |
5 | <link rel="SHORTCUT ICON" href="../icons/pyfav.png" type="image/png" /> | |
6 | <link rel='start' href='../index.html' title='Python Documentation Index' /> | |
7 | <link rel="first" href="lib.html" title='Python Library Reference' /> | |
8 | <link rel='contents' href='contents.html' title="Contents" /> | |
9 | <link rel='index' href='genindex.html' title='Index' /> | |
10 | <link rel='last' href='about.html' title='About this document...' /> | |
11 | <link rel='help' href='about.html' title='About this document...' /> | |
12 | <link rel="prev" href="module-pprint.html" /> | |
13 | <link rel="parent" href="module-pprint.html" /> | |
14 | <link rel="next" href="module-repr.html" /> | |
15 | <meta name='aesop' content='information' /> | |
16 | <title>3.27.1 PrettyPrinter Objects</title> | |
17 | </head> | |
18 | <body> | |
19 | <DIV CLASS="navigation"> | |
20 | <div id='top-navigation-panel' xml:id='top-navigation-panel'> | |
21 | <table align="center" width="100%" cellpadding="0" cellspacing="2"> | |
22 | <tr> | |
23 | <td class='online-navigation'><a rel="prev" title="3.27 pprint " | |
24 | href="module-pprint.html"><img src='../icons/previous.png' | |
25 | border='0' height='32' alt='Previous Page' width='32' /></A></td> | |
26 | <td class='online-navigation'><a rel="parent" title="3.27 pprint " | |
27 | href="module-pprint.html"><img src='../icons/up.png' | |
28 | border='0' height='32' alt='Up One Level' width='32' /></A></td> | |
29 | <td class='online-navigation'><a rel="next" title="3.28 repr " | |
30 | href="module-repr.html"><img src='../icons/next.png' | |
31 | border='0' height='32' alt='Next Page' width='32' /></A></td> | |
32 | <td align="center" width="100%">Python Library Reference</td> | |
33 | <td class='online-navigation'><a rel="contents" title="Table of Contents" | |
34 | href="contents.html"><img src='../icons/contents.png' | |
35 | border='0' height='32' alt='Contents' width='32' /></A></td> | |
36 | <td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png' | |
37 | border='0' height='32' alt='Module Index' width='32' /></a></td> | |
38 | <td class='online-navigation'><a rel="index" title="Index" | |
39 | href="genindex.html"><img src='../icons/index.png' | |
40 | border='0' height='32' alt='Index' width='32' /></A></td> | |
41 | </tr></table> | |
42 | <div class='online-navigation'> | |
43 | <b class="navlabel">Previous:</b> | |
44 | <a class="sectref" rel="prev" href="module-pprint.html">3.27 pprint </A> | |
45 | <b class="navlabel">Up:</b> | |
46 | <a class="sectref" rel="parent" href="module-pprint.html">3.27 pprint </A> | |
47 | <b class="navlabel">Next:</b> | |
48 | <a class="sectref" rel="next" href="module-repr.html">3.28 repr </A> | |
49 | </div> | |
50 | <hr /></div> | |
51 | </DIV> | |
52 | <!--End of Navigation Panel--> | |
53 | ||
54 | <H2><A NAME="SECTION0052710000000000000000"></A> | |
55 | <A NAME="PrettyPrinter_Objects"></A> | |
56 | <BR> | |
57 | 3.27.1 PrettyPrinter Objects | |
58 | </H2> | |
59 | ||
60 | <P> | |
61 | <tt class="class">PrettyPrinter</tt> instances have the following methods: | |
62 | ||
63 | <P> | |
64 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
65 | <td><nobr><b><tt id='l2h-769' xml:id='l2h-769' class="method">pformat</tt></b>(</nobr></td> | |
66 | <td><var>object</var>)</td></tr></table></dt> | |
67 | <dd> | |
68 | Return the formatted representation of <var>object</var>. This takes into | |
69 | Account the options passed to the <tt class="class">PrettyPrinter</tt> constructor. | |
70 | </dl> | |
71 | ||
72 | <P> | |
73 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
74 | <td><nobr><b><tt id='l2h-770' xml:id='l2h-770' class="method">pprint</tt></b>(</nobr></td> | |
75 | <td><var>object</var>)</td></tr></table></dt> | |
76 | <dd> | |
77 | Print the formatted representation of <var>object</var> on the configured | |
78 | stream, followed by a newline. | |
79 | </dl> | |
80 | ||
81 | <P> | |
82 | The following methods provide the implementations for the | |
83 | corresponding functions of the same names. Using these methods on an | |
84 | instance is slightly more efficient since new <tt class="class">PrettyPrinter</tt> | |
85 | objects don't need to be created. | |
86 | ||
87 | <P> | |
88 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
89 | <td><nobr><b><tt id='l2h-771' xml:id='l2h-771' class="method">isreadable</tt></b>(</nobr></td> | |
90 | <td><var>object</var>)</td></tr></table></dt> | |
91 | <dd> | |
92 | Determine if the formatted representation of the object is | |
93 | ``readable,'' or can be used to reconstruct the value using | |
94 | <tt class="function">eval()</tt><a id='l2h-772' xml:id='l2h-772'></a>. Note that this returns false for | |
95 | recursive objects. If the <var>depth</var> parameter of the | |
96 | <tt class="class">PrettyPrinter</tt> is set and the object is deeper than allowed, | |
97 | this returns false. | |
98 | </dl> | |
99 | ||
100 | <P> | |
101 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
102 | <td><nobr><b><tt id='l2h-773' xml:id='l2h-773' class="method">isrecursive</tt></b>(</nobr></td> | |
103 | <td><var>object</var>)</td></tr></table></dt> | |
104 | <dd> | |
105 | Determine if the object requires a recursive representation. | |
106 | </dl> | |
107 | ||
108 | <P> | |
109 | This method is provided as a hook to allow subclasses to modify the | |
110 | way objects are converted to strings. The default implementation uses | |
111 | the internals of the <tt class="function">saferepr()</tt> implementation. | |
112 | ||
113 | <P> | |
114 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
115 | <td><nobr><b><tt id='l2h-774' xml:id='l2h-774' class="method">format</tt></b>(</nobr></td> | |
116 | <td><var>object, context, maxlevels, level</var>)</td></tr></table></dt> | |
117 | <dd> | |
118 | Returns three values: the formatted version of <var>object</var> as a | |
119 | string, a flag indicating whether the result is readable, and a flag | |
120 | indicating whether recursion was detected. The first argument is the | |
121 | object to be presented. The second is a dictionary which contains the | |
122 | <tt class="function">id()</tt> of objects that are part of the current presentation | |
123 | context (direct and indirect containers for <var>object</var> that are | |
124 | affecting the presentation) as the keys; if an object needs to be | |
125 | presented which is already represented in <var>context</var>, the third | |
126 | return value should be true. Recursive calls to the <tt class="method">format()</tt> | |
127 | method should add additional entries for containers to this | |
128 | dictionary. The fourth argument, <var>maxlevels</var>, gives the requested | |
129 | limit to recursion; this will be <code>0</code> if there is no requested | |
130 | limit. This argument should be passed unmodified to recursive calls. | |
131 | The fourth argument, <var>level</var> gives the current level; recursive | |
132 | calls should be passed a value less than that of the current call. | |
133 | ||
134 | <span class="versionnote">New in version 2.3.</span> | |
135 | ||
136 | </dl> | |
137 | ||
138 | <DIV CLASS="navigation"> | |
139 | <div class='online-navigation'> | |
140 | <p></p><hr /> | |
141 | <table align="center" width="100%" cellpadding="0" cellspacing="2"> | |
142 | <tr> | |
143 | <td class='online-navigation'><a rel="prev" title="3.27 pprint " | |
144 | href="module-pprint.html"><img src='../icons/previous.png' | |
145 | border='0' height='32' alt='Previous Page' width='32' /></A></td> | |
146 | <td class='online-navigation'><a rel="parent" title="3.27 pprint " | |
147 | href="module-pprint.html"><img src='../icons/up.png' | |
148 | border='0' height='32' alt='Up One Level' width='32' /></A></td> | |
149 | <td class='online-navigation'><a rel="next" title="3.28 repr " | |
150 | href="module-repr.html"><img src='../icons/next.png' | |
151 | border='0' height='32' alt='Next Page' width='32' /></A></td> | |
152 | <td align="center" width="100%">Python Library Reference</td> | |
153 | <td class='online-navigation'><a rel="contents" title="Table of Contents" | |
154 | href="contents.html"><img src='../icons/contents.png' | |
155 | border='0' height='32' alt='Contents' width='32' /></A></td> | |
156 | <td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png' | |
157 | border='0' height='32' alt='Module Index' width='32' /></a></td> | |
158 | <td class='online-navigation'><a rel="index" title="Index" | |
159 | href="genindex.html"><img src='../icons/index.png' | |
160 | border='0' height='32' alt='Index' width='32' /></A></td> | |
161 | </tr></table> | |
162 | <div class='online-navigation'> | |
163 | <b class="navlabel">Previous:</b> | |
164 | <a class="sectref" rel="prev" href="module-pprint.html">3.27 pprint </A> | |
165 | <b class="navlabel">Up:</b> | |
166 | <a class="sectref" rel="parent" href="module-pprint.html">3.27 pprint </A> | |
167 | <b class="navlabel">Next:</b> | |
168 | <a class="sectref" rel="next" href="module-repr.html">3.28 repr </A> | |
169 | </div> | |
170 | </div> | |
171 | <hr /> | |
172 | <span class="release-info">Release 2.4.2, documentation updated on 28 September 2005.</span> | |
173 | </DIV> | |
174 | <!--End of Navigation Panel--> | |
175 | <ADDRESS> | |
176 | See <i><a href="about.html">About this document...</a></i> for information on suggesting changes. | |
177 | </ADDRESS> | |
178 | </BODY> | |
179 | </HTML> |