Initial commit of OpenSPARC T2 design and verification files.
[OpenSPARC-T2-DV] / tools / src / nas,5.n2.os.2 / lib / python / html / python / lib / inspect-types.html
CommitLineData
86530b38
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="next" href="inspect-source.html" />
13<link rel="prev" href="module-inspect.html" />
14<link rel="parent" href="module-inspect.html" />
15<link rel="next" href="inspect-source.html" />
16<meta name='aesop' content='information' />
17<title>3.11.1 Types and members </title>
18</head>
19<body>
20<DIV CLASS="navigation">
21<div id='top-navigation-panel' xml:id='top-navigation-panel'>
22<table align="center" width="100%" cellpadding="0" cellspacing="2">
23<tr>
24<td class='online-navigation'><a rel="prev" title="3.11 inspect "
25 href="module-inspect.html"><img src='../icons/previous.png'
26 border='0' height='32' alt='Previous Page' width='32' /></A></td>
27<td class='online-navigation'><a rel="parent" title="3.11 inspect "
28 href="module-inspect.html"><img src='../icons/up.png'
29 border='0' height='32' alt='Up One Level' width='32' /></A></td>
30<td class='online-navigation'><a rel="next" title="3.11.2 Retrieving source code"
31 href="inspect-source.html"><img src='../icons/next.png'
32 border='0' height='32' alt='Next Page' width='32' /></A></td>
33<td align="center" width="100%">Python Library Reference</td>
34<td class='online-navigation'><a rel="contents" title="Table of Contents"
35 href="contents.html"><img src='../icons/contents.png'
36 border='0' height='32' alt='Contents' width='32' /></A></td>
37<td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png'
38 border='0' height='32' alt='Module Index' width='32' /></a></td>
39<td class='online-navigation'><a rel="index" title="Index"
40 href="genindex.html"><img src='../icons/index.png'
41 border='0' height='32' alt='Index' width='32' /></A></td>
42</tr></table>
43<div class='online-navigation'>
44<b class="navlabel">Previous:</b>
45<a class="sectref" rel="prev" href="module-inspect.html">3.11 inspect </A>
46<b class="navlabel">Up:</b>
47<a class="sectref" rel="parent" href="module-inspect.html">3.11 inspect </A>
48<b class="navlabel">Next:</b>
49<a class="sectref" rel="next" href="inspect-source.html">3.11.2 Retrieving source code</A>
50</div>
51<hr /></div>
52</DIV>
53<!--End of Navigation Panel-->
54
55<H2><A NAME="SECTION0051110000000000000000"></A><A NAME="inspect-types"></A>
56<BR>
573.11.1 Types and members
58
59</H2>
60
61<P>
62The <tt class="function">getmembers()</tt> function retrieves the members
63of an object such as a class or module.
64The eleven functions whose names begin with ``is'' are mainly
65provided as convenient choices for the second argument to
66<tt class="function">getmembers()</tt>. They also help you determine when
67you can expect to find the following special attributes:
68
69<P>
70<div class="center"><table class="realtable">
71 <thead>
72 <tr>
73 <th class="center">Type</th>
74 <th class="left" >Attribute</th>
75 <th class="left" >Description</th>
76 <th class="center">Notes</th>
77 </tr>
78 </thead>
79 <tbody>
80 <tr><td class="center" valign="baseline">module</td>
81 <td class="left" >__doc__</td>
82 <td class="left" >documentation string</td>
83 <td class="center"></td></tr>
84 <tr><td class="center" valign="baseline"></td>
85 <td class="left" >__file__</td>
86 <td class="left" >filename (missing for built-in modules)</td>
87 <td class="center"></td></tr>
88
89 <tr><td class="center" valign="baseline">class</td>
90 <td class="left" >__doc__</td>
91 <td class="left" >documentation string</td>
92 <td class="center"></td></tr>
93 <tr><td class="center" valign="baseline"></td>
94 <td class="left" >__module__</td>
95 <td class="left" >name of module in which this class was defined</td>
96 <td class="center"></td></tr>
97
98 <tr><td class="center" valign="baseline">method</td>
99 <td class="left" >__doc__</td>
100 <td class="left" >documentation string</td>
101 <td class="center"></td></tr>
102 <tr><td class="center" valign="baseline"></td>
103 <td class="left" >__name__</td>
104 <td class="left" >name with which this method was defined</td>
105 <td class="center"></td></tr>
106 <tr><td class="center" valign="baseline"></td>
107 <td class="left" >im_class</td>
108 <td class="left" >class object that asked for this method</td>
109 <td class="center">(1)</td></tr>
110 <tr><td class="center" valign="baseline"></td>
111 <td class="left" >im_func</td>
112 <td class="left" >function object containing implementation of method</td>
113 <td class="center"></td></tr>
114 <tr><td class="center" valign="baseline"></td>
115 <td class="left" >im_self</td>
116 <td class="left" >instance to which this method is bound, or <code>None</code></td>
117 <td class="center"></td></tr>
118
119 <tr><td class="center" valign="baseline">function</td>
120 <td class="left" >__doc__</td>
121 <td class="left" >documentation string</td>
122 <td class="center"></td></tr>
123 <tr><td class="center" valign="baseline"></td>
124 <td class="left" >__name__</td>
125 <td class="left" >name with which this function was defined</td>
126 <td class="center"></td></tr>
127 <tr><td class="center" valign="baseline"></td>
128 <td class="left" >func_code</td>
129 <td class="left" >code object containing compiled function bytecode</td>
130 <td class="center"></td></tr>
131 <tr><td class="center" valign="baseline"></td>
132 <td class="left" >func_defaults</td>
133 <td class="left" >tuple of any default values for arguments</td>
134 <td class="center"></td></tr>
135 <tr><td class="center" valign="baseline"></td>
136 <td class="left" >func_doc</td>
137 <td class="left" >(same as __doc__)</td>
138 <td class="center"></td></tr>
139 <tr><td class="center" valign="baseline"></td>
140 <td class="left" >func_globals</td>
141 <td class="left" >global namespace in which this function was defined</td>
142 <td class="center"></td></tr>
143 <tr><td class="center" valign="baseline"></td>
144 <td class="left" >func_name</td>
145 <td class="left" >(same as __name__)</td>
146 <td class="center"></td></tr>
147
148 <tr><td class="center" valign="baseline">traceback</td>
149 <td class="left" >tb_frame</td>
150 <td class="left" >frame object at this level</td>
151 <td class="center"></td></tr>
152 <tr><td class="center" valign="baseline"></td>
153 <td class="left" >tb_lasti</td>
154 <td class="left" >index of last attempted instruction in bytecode</td>
155 <td class="center"></td></tr>
156 <tr><td class="center" valign="baseline"></td>
157 <td class="left" >tb_lineno</td>
158 <td class="left" >current line number in Python source code</td>
159 <td class="center"></td></tr>
160 <tr><td class="center" valign="baseline"></td>
161 <td class="left" >tb_next</td>
162 <td class="left" >next inner traceback object (called by this level)</td>
163 <td class="center"></td></tr>
164
165 <tr><td class="center" valign="baseline">frame</td>
166 <td class="left" >f_back</td>
167 <td class="left" >next outer frame object (this frame's caller)</td>
168 <td class="center"></td></tr>
169 <tr><td class="center" valign="baseline"></td>
170 <td class="left" >f_builtins</td>
171 <td class="left" >built-in namespace seen by this frame</td>
172 <td class="center"></td></tr>
173 <tr><td class="center" valign="baseline"></td>
174 <td class="left" >f_code</td>
175 <td class="left" >code object being executed in this frame</td>
176 <td class="center"></td></tr>
177 <tr><td class="center" valign="baseline"></td>
178 <td class="left" >f_exc_traceback</td>
179 <td class="left" >traceback if raised in this frame, or <code>None</code></td>
180 <td class="center"></td></tr>
181 <tr><td class="center" valign="baseline"></td>
182 <td class="left" >f_exc_type</td>
183 <td class="left" >exception type if raised in this frame, or <code>None</code></td>
184 <td class="center"></td></tr>
185 <tr><td class="center" valign="baseline"></td>
186 <td class="left" >f_exc_value</td>
187 <td class="left" >exception value if raised in this frame, or <code>None</code></td>
188 <td class="center"></td></tr>
189 <tr><td class="center" valign="baseline"></td>
190 <td class="left" >f_globals</td>
191 <td class="left" >global namespace seen by this frame</td>
192 <td class="center"></td></tr>
193 <tr><td class="center" valign="baseline"></td>
194 <td class="left" >f_lasti</td>
195 <td class="left" >index of last attempted instruction in bytecode</td>
196 <td class="center"></td></tr>
197 <tr><td class="center" valign="baseline"></td>
198 <td class="left" >f_lineno</td>
199 <td class="left" >current line number in Python source code</td>
200 <td class="center"></td></tr>
201 <tr><td class="center" valign="baseline"></td>
202 <td class="left" >f_locals</td>
203 <td class="left" >local namespace seen by this frame</td>
204 <td class="center"></td></tr>
205 <tr><td class="center" valign="baseline"></td>
206 <td class="left" >f_restricted</td>
207 <td class="left" >0 or 1 if frame is in restricted execution mode</td>
208 <td class="center"></td></tr>
209 <tr><td class="center" valign="baseline"></td>
210 <td class="left" >f_trace</td>
211 <td class="left" >tracing function for this frame, or <code>None</code></td>
212 <td class="center"></td></tr>
213
214 <tr><td class="center" valign="baseline">code</td>
215 <td class="left" >co_argcount</td>
216 <td class="left" >number of arguments (not including * or ** args)</td>
217 <td class="center"></td></tr>
218 <tr><td class="center" valign="baseline"></td>
219 <td class="left" >co_code</td>
220 <td class="left" >string of raw compiled bytecode</td>
221 <td class="center"></td></tr>
222 <tr><td class="center" valign="baseline"></td>
223 <td class="left" >co_consts</td>
224 <td class="left" >tuple of constants used in the bytecode</td>
225 <td class="center"></td></tr>
226 <tr><td class="center" valign="baseline"></td>
227 <td class="left" >co_filename</td>
228 <td class="left" >name of file in which this code object was created</td>
229 <td class="center"></td></tr>
230 <tr><td class="center" valign="baseline"></td>
231 <td class="left" >co_firstlineno</td>
232 <td class="left" >number of first line in Python source code</td>
233 <td class="center"></td></tr>
234 <tr><td class="center" valign="baseline"></td>
235 <td class="left" >co_flags</td>
236 <td class="left" >bitmap: 1=optimized <code>|</code> 2=newlocals <code>|</code> 4=*arg <code>|</code> 8=**arg</td>
237 <td class="center"></td></tr>
238 <tr><td class="center" valign="baseline"></td>
239 <td class="left" >co_lnotab</td>
240 <td class="left" >encoded mapping of line numbers to bytecode indices</td>
241 <td class="center"></td></tr>
242 <tr><td class="center" valign="baseline"></td>
243 <td class="left" >co_name</td>
244 <td class="left" >name with which this code object was defined</td>
245 <td class="center"></td></tr>
246 <tr><td class="center" valign="baseline"></td>
247 <td class="left" >co_names</td>
248 <td class="left" >tuple of names of local variables</td>
249 <td class="center"></td></tr>
250 <tr><td class="center" valign="baseline"></td>
251 <td class="left" >co_nlocals</td>
252 <td class="left" >number of local variables</td>
253 <td class="center"></td></tr>
254 <tr><td class="center" valign="baseline"></td>
255 <td class="left" >co_stacksize</td>
256 <td class="left" >virtual machine stack space required</td>
257 <td class="center"></td></tr>
258 <tr><td class="center" valign="baseline"></td>
259 <td class="left" >co_varnames</td>
260 <td class="left" >tuple of names of arguments and local variables</td>
261 <td class="center"></td></tr>
262
263 <tr><td class="center" valign="baseline">builtin</td>
264 <td class="left" >__doc__</td>
265 <td class="left" >documentation string</td>
266 <td class="center"></td></tr>
267 <tr><td class="center" valign="baseline"></td>
268 <td class="left" >__name__</td>
269 <td class="left" >original name of this function or method</td>
270 <td class="center"></td></tr>
271 <tr><td class="center" valign="baseline"></td>
272 <td class="left" >__self__</td>
273 <td class="left" >instance to which a method is bound, or <code>None</code></td>
274 <td class="center"></td></tr></tbody>
275</table></div>
276
277<P>
278Note:
279<DL>
280<DT><STRONG>(1)</STRONG></DT>
281<DD>
282<span class="versionnote">Changed in version 2.2:
283<tt class="member">im_class</tt> used to refer to the class that
284 defined the method.</span>
285
286</DD>
287</DL>
288
289<P>
290<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
291 <td><nobr><b><tt id='l2h-571' xml:id='l2h-571' class="function">getmembers</tt></b>(</nobr></td>
292 <td><var>object</var><big>[</big><var>, predicate</var><big>]</big><var></var>)</td></tr></table></dt>
293<dd>
294 Return all the members of an object in a list of (name, value) pairs
295 sorted by name. If the optional <var>predicate</var> argument is supplied,
296 only members for which the predicate returns a true value are included.
297</dl>
298
299<P>
300<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
301 <td><nobr><b><tt id='l2h-572' xml:id='l2h-572' class="function">getmoduleinfo</tt></b>(</nobr></td>
302 <td><var>path</var>)</td></tr></table></dt>
303<dd>
304 Return a tuple of values that describe how Python will interpret the
305 file identified by <var>path</var> if it is a module, or <code>None</code> if
306 it would not be identified as a module. The return tuple is
307 <code>(<var>name</var>, <var>suffix</var>, <var>mode</var>, <var>mtype</var>)</code>, where
308 <var>name</var> is the name of the module without the name of any
309 enclosing package, <var>suffix</var> is the trailing part of the file
310 name (which may not be a dot-delimited extension), <var>mode</var> is the
311 <tt class="function">open()</tt> mode that would be used (<code>'r'</code> or
312 <code>'rb'</code>), and <var>mtype</var> is an integer giving the type of the
313 module. <var>mtype</var> will have a value which can be compared to the
314 constants defined in the <tt class="module"><a href="module-imp.html">imp</a></tt> module; see the
315 documentation for that module for more information on module types.
316</dl>
317
318<P>
319<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
320 <td><nobr><b><tt id='l2h-573' xml:id='l2h-573' class="function">getmodulename</tt></b>(</nobr></td>
321 <td><var>path</var>)</td></tr></table></dt>
322<dd>
323 Return the name of the module named by the file <var>path</var>, without
324 including the names of enclosing packages. This uses the same
325 algorithm as the interpreter uses when searching for modules. If
326 the name cannot be matched according to the interpreter's rules,
327 <code>None</code> is returned.
328</dl>
329
330<P>
331<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
332 <td><nobr><b><tt id='l2h-574' xml:id='l2h-574' class="function">ismodule</tt></b>(</nobr></td>
333 <td><var>object</var>)</td></tr></table></dt>
334<dd>
335 Return true if the object is a module.
336</dl>
337
338<P>
339<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
340 <td><nobr><b><tt id='l2h-575' xml:id='l2h-575' class="function">isclass</tt></b>(</nobr></td>
341 <td><var>object</var>)</td></tr></table></dt>
342<dd>
343 Return true if the object is a class.
344</dl>
345
346<P>
347<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
348 <td><nobr><b><tt id='l2h-576' xml:id='l2h-576' class="function">ismethod</tt></b>(</nobr></td>
349 <td><var>object</var>)</td></tr></table></dt>
350<dd>
351 Return true if the object is a method.
352</dl>
353
354<P>
355<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
356 <td><nobr><b><tt id='l2h-577' xml:id='l2h-577' class="function">isfunction</tt></b>(</nobr></td>
357 <td><var>object</var>)</td></tr></table></dt>
358<dd>
359 Return true if the object is a Python function or unnamed (lambda) function.
360</dl>
361
362<P>
363<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
364 <td><nobr><b><tt id='l2h-578' xml:id='l2h-578' class="function">istraceback</tt></b>(</nobr></td>
365 <td><var>object</var>)</td></tr></table></dt>
366<dd>
367 Return true if the object is a traceback.
368</dl>
369
370<P>
371<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
372 <td><nobr><b><tt id='l2h-579' xml:id='l2h-579' class="function">isframe</tt></b>(</nobr></td>
373 <td><var>object</var>)</td></tr></table></dt>
374<dd>
375 Return true if the object is a frame.
376</dl>
377
378<P>
379<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
380 <td><nobr><b><tt id='l2h-580' xml:id='l2h-580' class="function">iscode</tt></b>(</nobr></td>
381 <td><var>object</var>)</td></tr></table></dt>
382<dd>
383 Return true if the object is a code.
384</dl>
385
386<P>
387<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
388 <td><nobr><b><tt id='l2h-581' xml:id='l2h-581' class="function">isbuiltin</tt></b>(</nobr></td>
389 <td><var>object</var>)</td></tr></table></dt>
390<dd>
391 Return true if the object is a built-in function.
392</dl>
393
394<P>
395<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
396 <td><nobr><b><tt id='l2h-582' xml:id='l2h-582' class="function">isroutine</tt></b>(</nobr></td>
397 <td><var>object</var>)</td></tr></table></dt>
398<dd>
399 Return true if the object is a user-defined or built-in function or method.
400</dl>
401
402<P>
403<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
404 <td><nobr><b><tt id='l2h-583' xml:id='l2h-583' class="function">ismethoddescriptor</tt></b>(</nobr></td>
405 <td><var>object</var>)</td></tr></table></dt>
406<dd>
407 Return true if the object is a method descriptor, but not if ismethod() or
408 isclass() or isfunction() are true.
409
410<P>
411This is new as of Python 2.2, and, for example, is true of int.__add__.
412 An object passing this test has a __get__ attribute but not a __set__
413 attribute, but beyond that the set of attributes varies. __name__ is
414 usually sensible, and __doc__ often is.
415
416<P>
417Methods implemented via descriptors that also pass one of the other
418 tests return false from the ismethoddescriptor() test, simply because
419 the other tests promise more - you can, e.g., count on having the
420 im_func attribute (etc) when an object passes ismethod().
421</dl>
422
423<P>
424<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
425 <td><nobr><b><tt id='l2h-584' xml:id='l2h-584' class="function">isdatadescriptor</tt></b>(</nobr></td>
426 <td><var>object</var>)</td></tr></table></dt>
427<dd>
428 Return true if the object is a data descriptor.
429
430<P>
431Data descriptors have both a __get__ and a __set__ attribute. Examples are
432 properties (defined in Python) and getsets and members (defined in C).
433 Typically, data descriptors will also have __name__ and __doc__ attributes
434 (properties, getsets, and members have both of these attributes), but this
435 is not guaranteed.
436
437<span class="versionnote">New in version 2.3.</span>
438
439</dl>
440
441<P>
442
443<DIV CLASS="navigation">
444<div class='online-navigation'>
445<p></p><hr />
446<table align="center" width="100%" cellpadding="0" cellspacing="2">
447<tr>
448<td class='online-navigation'><a rel="prev" title="3.11 inspect "
449 href="module-inspect.html"><img src='../icons/previous.png'
450 border='0' height='32' alt='Previous Page' width='32' /></A></td>
451<td class='online-navigation'><a rel="parent" title="3.11 inspect "
452 href="module-inspect.html"><img src='../icons/up.png'
453 border='0' height='32' alt='Up One Level' width='32' /></A></td>
454<td class='online-navigation'><a rel="next" title="3.11.2 Retrieving source code"
455 href="inspect-source.html"><img src='../icons/next.png'
456 border='0' height='32' alt='Next Page' width='32' /></A></td>
457<td align="center" width="100%">Python Library Reference</td>
458<td class='online-navigation'><a rel="contents" title="Table of Contents"
459 href="contents.html"><img src='../icons/contents.png'
460 border='0' height='32' alt='Contents' width='32' /></A></td>
461<td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png'
462 border='0' height='32' alt='Module Index' width='32' /></a></td>
463<td class='online-navigation'><a rel="index" title="Index"
464 href="genindex.html"><img src='../icons/index.png'
465 border='0' height='32' alt='Index' width='32' /></A></td>
466</tr></table>
467<div class='online-navigation'>
468<b class="navlabel">Previous:</b>
469<a class="sectref" rel="prev" href="module-inspect.html">3.11 inspect </A>
470<b class="navlabel">Up:</b>
471<a class="sectref" rel="parent" href="module-inspect.html">3.11 inspect </A>
472<b class="navlabel">Next:</b>
473<a class="sectref" rel="next" href="inspect-source.html">3.11.2 Retrieving source code</A>
474</div>
475</div>
476<hr />
477<span class="release-info">Release 2.4.2, documentation updated on 28 September 2005.</span>
478</DIV>
479<!--End of Navigation Panel-->
480<ADDRESS>
481See <i><a href="about.html">About this document...</a></i> for information on suggesting changes.
482</ADDRESS>
483</BODY>
484</HTML>