Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / devtools / amd64 / html / python / lib / inspect-types.html
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<link rel="STYLESHEET" href="lib.css" type='text/css' />
<link rel="SHORTCUT ICON" href="../icons/pyfav.png" type="image/png" />
<link rel='start' href='../index.html' title='Python Documentation Index' />
<link rel="first" href="lib.html" title='Python Library Reference' />
<link rel='contents' href='contents.html' title="Contents" />
<link rel='index' href='genindex.html' title='Index' />
<link rel='last' href='about.html' title='About this document...' />
<link rel='help' href='about.html' title='About this document...' />
<link rel="next" href="inspect-source.html" />
<link rel="prev" href="module-inspect.html" />
<link rel="parent" href="module-inspect.html" />
<link rel="next" href="inspect-source.html" />
<meta name='aesop' content='information' />
<title>3.11.1 Types and members </title>
</head>
<body>
<DIV CLASS="navigation">
<div id='top-navigation-panel' xml:id='top-navigation-panel'>
<table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td class='online-navigation'><a rel="prev" title="3.11 inspect "
href="module-inspect.html"><img src='../icons/previous.png'
border='0' height='32' alt='Previous Page' width='32' /></A></td>
<td class='online-navigation'><a rel="parent" title="3.11 inspect "
href="module-inspect.html"><img src='../icons/up.png'
border='0' height='32' alt='Up One Level' width='32' /></A></td>
<td class='online-navigation'><a rel="next" title="3.11.2 Retrieving source code"
href="inspect-source.html"><img src='../icons/next.png'
border='0' height='32' alt='Next Page' width='32' /></A></td>
<td align="center" width="100%">Python Library Reference</td>
<td class='online-navigation'><a rel="contents" title="Table of Contents"
href="contents.html"><img src='../icons/contents.png'
border='0' height='32' alt='Contents' width='32' /></A></td>
<td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png'
border='0' height='32' alt='Module Index' width='32' /></a></td>
<td class='online-navigation'><a rel="index" title="Index"
href="genindex.html"><img src='../icons/index.png'
border='0' height='32' alt='Index' width='32' /></A></td>
</tr></table>
<div class='online-navigation'>
<b class="navlabel">Previous:</b>
<a class="sectref" rel="prev" href="module-inspect.html">3.11 inspect </A>
<b class="navlabel">Up:</b>
<a class="sectref" rel="parent" href="module-inspect.html">3.11 inspect </A>
<b class="navlabel">Next:</b>
<a class="sectref" rel="next" href="inspect-source.html">3.11.2 Retrieving source code</A>
</div>
<hr /></div>
</DIV>
<!--End of Navigation Panel-->
<H2><A NAME="SECTION0051110000000000000000"></A><A NAME="inspect-types"></A>
<BR>
3.11.1 Types and members
</H2>
<P>
The <tt class="function">getmembers()</tt> function retrieves the members
of an object such as a class or module.
The eleven functions whose names begin with ``is'' are mainly
provided as convenient choices for the second argument to
<tt class="function">getmembers()</tt>. They also help you determine when
you can expect to find the following special attributes:
<P>
<div class="center"><table class="realtable">
<thead>
<tr>
<th class="center">Type</th>
<th class="left" >Attribute</th>
<th class="left" >Description</th>
<th class="center">Notes</th>
</tr>
</thead>
<tbody>
<tr><td class="center" valign="baseline">module</td>
<td class="left" >__doc__</td>
<td class="left" >documentation string</td>
<td class="center"></td></tr>
<tr><td class="center" valign="baseline"></td>
<td class="left" >__file__</td>
<td class="left" >filename (missing for built-in modules)</td>
<td class="center"></td></tr>
<tr><td class="center" valign="baseline">class</td>
<td class="left" >__doc__</td>
<td class="left" >documentation string</td>
<td class="center"></td></tr>
<tr><td class="center" valign="baseline"></td>
<td class="left" >__module__</td>
<td class="left" >name of module in which this class was defined</td>
<td class="center"></td></tr>
<tr><td class="center" valign="baseline">method</td>
<td class="left" >__doc__</td>
<td class="left" >documentation string</td>
<td class="center"></td></tr>
<tr><td class="center" valign="baseline"></td>
<td class="left" >__name__</td>
<td class="left" >name with which this method was defined</td>
<td class="center"></td></tr>
<tr><td class="center" valign="baseline"></td>
<td class="left" >im_class</td>
<td class="left" >class object that asked for this method</td>
<td class="center">(1)</td></tr>
<tr><td class="center" valign="baseline"></td>
<td class="left" >im_func</td>
<td class="left" >function object containing implementation of method</td>
<td class="center"></td></tr>
<tr><td class="center" valign="baseline"></td>
<td class="left" >im_self</td>
<td class="left" >instance to which this method is bound, or <code>None</code></td>
<td class="center"></td></tr>
<tr><td class="center" valign="baseline">function</td>
<td class="left" >__doc__</td>
<td class="left" >documentation string</td>
<td class="center"></td></tr>
<tr><td class="center" valign="baseline"></td>
<td class="left" >__name__</td>
<td class="left" >name with which this function was defined</td>
<td class="center"></td></tr>
<tr><td class="center" valign="baseline"></td>
<td class="left" >func_code</td>
<td class="left" >code object containing compiled function bytecode</td>
<td class="center"></td></tr>
<tr><td class="center" valign="baseline"></td>
<td class="left" >func_defaults</td>
<td class="left" >tuple of any default values for arguments</td>
<td class="center"></td></tr>
<tr><td class="center" valign="baseline"></td>
<td class="left" >func_doc</td>
<td class="left" >(same as __doc__)</td>
<td class="center"></td></tr>
<tr><td class="center" valign="baseline"></td>
<td class="left" >func_globals</td>
<td class="left" >global namespace in which this function was defined</td>
<td class="center"></td></tr>
<tr><td class="center" valign="baseline"></td>
<td class="left" >func_name</td>
<td class="left" >(same as __name__)</td>
<td class="center"></td></tr>
<tr><td class="center" valign="baseline">traceback</td>
<td class="left" >tb_frame</td>
<td class="left" >frame object at this level</td>
<td class="center"></td></tr>
<tr><td class="center" valign="baseline"></td>
<td class="left" >tb_lasti</td>
<td class="left" >index of last attempted instruction in bytecode</td>
<td class="center"></td></tr>
<tr><td class="center" valign="baseline"></td>
<td class="left" >tb_lineno</td>
<td class="left" >current line number in Python source code</td>
<td class="center"></td></tr>
<tr><td class="center" valign="baseline"></td>
<td class="left" >tb_next</td>
<td class="left" >next inner traceback object (called by this level)</td>
<td class="center"></td></tr>
<tr><td class="center" valign="baseline">frame</td>
<td class="left" >f_back</td>
<td class="left" >next outer frame object (this frame's caller)</td>
<td class="center"></td></tr>
<tr><td class="center" valign="baseline"></td>
<td class="left" >f_builtins</td>
<td class="left" >built-in namespace seen by this frame</td>
<td class="center"></td></tr>
<tr><td class="center" valign="baseline"></td>
<td class="left" >f_code</td>
<td class="left" >code object being executed in this frame</td>
<td class="center"></td></tr>
<tr><td class="center" valign="baseline"></td>
<td class="left" >f_exc_traceback</td>
<td class="left" >traceback if raised in this frame, or <code>None</code></td>
<td class="center"></td></tr>
<tr><td class="center" valign="baseline"></td>
<td class="left" >f_exc_type</td>
<td class="left" >exception type if raised in this frame, or <code>None</code></td>
<td class="center"></td></tr>
<tr><td class="center" valign="baseline"></td>
<td class="left" >f_exc_value</td>
<td class="left" >exception value if raised in this frame, or <code>None</code></td>
<td class="center"></td></tr>
<tr><td class="center" valign="baseline"></td>
<td class="left" >f_globals</td>
<td class="left" >global namespace seen by this frame</td>
<td class="center"></td></tr>
<tr><td class="center" valign="baseline"></td>
<td class="left" >f_lasti</td>
<td class="left" >index of last attempted instruction in bytecode</td>
<td class="center"></td></tr>
<tr><td class="center" valign="baseline"></td>
<td class="left" >f_lineno</td>
<td class="left" >current line number in Python source code</td>
<td class="center"></td></tr>
<tr><td class="center" valign="baseline"></td>
<td class="left" >f_locals</td>
<td class="left" >local namespace seen by this frame</td>
<td class="center"></td></tr>
<tr><td class="center" valign="baseline"></td>
<td class="left" >f_restricted</td>
<td class="left" >0 or 1 if frame is in restricted execution mode</td>
<td class="center"></td></tr>
<tr><td class="center" valign="baseline"></td>
<td class="left" >f_trace</td>
<td class="left" >tracing function for this frame, or <code>None</code></td>
<td class="center"></td></tr>
<tr><td class="center" valign="baseline">code</td>
<td class="left" >co_argcount</td>
<td class="left" >number of arguments (not including * or ** args)</td>
<td class="center"></td></tr>
<tr><td class="center" valign="baseline"></td>
<td class="left" >co_code</td>
<td class="left" >string of raw compiled bytecode</td>
<td class="center"></td></tr>
<tr><td class="center" valign="baseline"></td>
<td class="left" >co_consts</td>
<td class="left" >tuple of constants used in the bytecode</td>
<td class="center"></td></tr>
<tr><td class="center" valign="baseline"></td>
<td class="left" >co_filename</td>
<td class="left" >name of file in which this code object was created</td>
<td class="center"></td></tr>
<tr><td class="center" valign="baseline"></td>
<td class="left" >co_firstlineno</td>
<td class="left" >number of first line in Python source code</td>
<td class="center"></td></tr>
<tr><td class="center" valign="baseline"></td>
<td class="left" >co_flags</td>
<td class="left" >bitmap: 1=optimized <code>|</code> 2=newlocals <code>|</code> 4=*arg <code>|</code> 8=**arg</td>
<td class="center"></td></tr>
<tr><td class="center" valign="baseline"></td>
<td class="left" >co_lnotab</td>
<td class="left" >encoded mapping of line numbers to bytecode indices</td>
<td class="center"></td></tr>
<tr><td class="center" valign="baseline"></td>
<td class="left" >co_name</td>
<td class="left" >name with which this code object was defined</td>
<td class="center"></td></tr>
<tr><td class="center" valign="baseline"></td>
<td class="left" >co_names</td>
<td class="left" >tuple of names of local variables</td>
<td class="center"></td></tr>
<tr><td class="center" valign="baseline"></td>
<td class="left" >co_nlocals</td>
<td class="left" >number of local variables</td>
<td class="center"></td></tr>
<tr><td class="center" valign="baseline"></td>
<td class="left" >co_stacksize</td>
<td class="left" >virtual machine stack space required</td>
<td class="center"></td></tr>
<tr><td class="center" valign="baseline"></td>
<td class="left" >co_varnames</td>
<td class="left" >tuple of names of arguments and local variables</td>
<td class="center"></td></tr>
<tr><td class="center" valign="baseline">builtin</td>
<td class="left" >__doc__</td>
<td class="left" >documentation string</td>
<td class="center"></td></tr>
<tr><td class="center" valign="baseline"></td>
<td class="left" >__name__</td>
<td class="left" >original name of this function or method</td>
<td class="center"></td></tr>
<tr><td class="center" valign="baseline"></td>
<td class="left" >__self__</td>
<td class="left" >instance to which a method is bound, or <code>None</code></td>
<td class="center"></td></tr></tbody>
</table></div>
<P>
Note:
<DL>
<DT><STRONG>(1)</STRONG></DT>
<DD>
<span class="versionnote">Changed in version 2.2:
<tt class="member">im_class</tt> used to refer to the class that
defined the method.</span>
</DD>
</DL>
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-571' xml:id='l2h-571' class="function">getmembers</tt></b>(</nobr></td>
<td><var>object</var><big>[</big><var>, predicate</var><big>]</big><var></var>)</td></tr></table></dt>
<dd>
Return all the members of an object in a list of (name, value) pairs
sorted by name. If the optional <var>predicate</var> argument is supplied,
only members for which the predicate returns a true value are included.
</dl>
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-572' xml:id='l2h-572' class="function">getmoduleinfo</tt></b>(</nobr></td>
<td><var>path</var>)</td></tr></table></dt>
<dd>
Return a tuple of values that describe how Python will interpret the
file identified by <var>path</var> if it is a module, or <code>None</code> if
it would not be identified as a module. The return tuple is
<code>(<var>name</var>, <var>suffix</var>, <var>mode</var>, <var>mtype</var>)</code>, where
<var>name</var> is the name of the module without the name of any
enclosing package, <var>suffix</var> is the trailing part of the file
name (which may not be a dot-delimited extension), <var>mode</var> is the
<tt class="function">open()</tt> mode that would be used (<code>'r'</code> or
<code>'rb'</code>), and <var>mtype</var> is an integer giving the type of the
module. <var>mtype</var> will have a value which can be compared to the
constants defined in the <tt class="module"><a href="module-imp.html">imp</a></tt> module; see the
documentation for that module for more information on module types.
</dl>
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-573' xml:id='l2h-573' class="function">getmodulename</tt></b>(</nobr></td>
<td><var>path</var>)</td></tr></table></dt>
<dd>
Return the name of the module named by the file <var>path</var>, without
including the names of enclosing packages. This uses the same
algorithm as the interpreter uses when searching for modules. If
the name cannot be matched according to the interpreter's rules,
<code>None</code> is returned.
</dl>
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-574' xml:id='l2h-574' class="function">ismodule</tt></b>(</nobr></td>
<td><var>object</var>)</td></tr></table></dt>
<dd>
Return true if the object is a module.
</dl>
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-575' xml:id='l2h-575' class="function">isclass</tt></b>(</nobr></td>
<td><var>object</var>)</td></tr></table></dt>
<dd>
Return true if the object is a class.
</dl>
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-576' xml:id='l2h-576' class="function">ismethod</tt></b>(</nobr></td>
<td><var>object</var>)</td></tr></table></dt>
<dd>
Return true if the object is a method.
</dl>
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-577' xml:id='l2h-577' class="function">isfunction</tt></b>(</nobr></td>
<td><var>object</var>)</td></tr></table></dt>
<dd>
Return true if the object is a Python function or unnamed (lambda) function.
</dl>
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-578' xml:id='l2h-578' class="function">istraceback</tt></b>(</nobr></td>
<td><var>object</var>)</td></tr></table></dt>
<dd>
Return true if the object is a traceback.
</dl>
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-579' xml:id='l2h-579' class="function">isframe</tt></b>(</nobr></td>
<td><var>object</var>)</td></tr></table></dt>
<dd>
Return true if the object is a frame.
</dl>
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-580' xml:id='l2h-580' class="function">iscode</tt></b>(</nobr></td>
<td><var>object</var>)</td></tr></table></dt>
<dd>
Return true if the object is a code.
</dl>
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-581' xml:id='l2h-581' class="function">isbuiltin</tt></b>(</nobr></td>
<td><var>object</var>)</td></tr></table></dt>
<dd>
Return true if the object is a built-in function.
</dl>
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-582' xml:id='l2h-582' class="function">isroutine</tt></b>(</nobr></td>
<td><var>object</var>)</td></tr></table></dt>
<dd>
Return true if the object is a user-defined or built-in function or method.
</dl>
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-583' xml:id='l2h-583' class="function">ismethoddescriptor</tt></b>(</nobr></td>
<td><var>object</var>)</td></tr></table></dt>
<dd>
Return true if the object is a method descriptor, but not if ismethod() or
isclass() or isfunction() are true.
<P>
This is new as of Python 2.2, and, for example, is true of int.__add__.
An object passing this test has a __get__ attribute but not a __set__
attribute, but beyond that the set of attributes varies. __name__ is
usually sensible, and __doc__ often is.
<P>
Methods implemented via descriptors that also pass one of the other
tests return false from the ismethoddescriptor() test, simply because
the other tests promise more - you can, e.g., count on having the
im_func attribute (etc) when an object passes ismethod().
</dl>
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-584' xml:id='l2h-584' class="function">isdatadescriptor</tt></b>(</nobr></td>
<td><var>object</var>)</td></tr></table></dt>
<dd>
Return true if the object is a data descriptor.
<P>
Data descriptors have both a __get__ and a __set__ attribute. Examples are
properties (defined in Python) and getsets and members (defined in C).
Typically, data descriptors will also have __name__ and __doc__ attributes
(properties, getsets, and members have both of these attributes), but this
is not guaranteed.
<span class="versionnote">New in version 2.3.</span>
</dl>
<P>
<DIV CLASS="navigation">
<div class='online-navigation'>
<p></p><hr />
<table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td class='online-navigation'><a rel="prev" title="3.11 inspect "
href="module-inspect.html"><img src='../icons/previous.png'
border='0' height='32' alt='Previous Page' width='32' /></A></td>
<td class='online-navigation'><a rel="parent" title="3.11 inspect "
href="module-inspect.html"><img src='../icons/up.png'
border='0' height='32' alt='Up One Level' width='32' /></A></td>
<td class='online-navigation'><a rel="next" title="3.11.2 Retrieving source code"
href="inspect-source.html"><img src='../icons/next.png'
border='0' height='32' alt='Next Page' width='32' /></A></td>
<td align="center" width="100%">Python Library Reference</td>
<td class='online-navigation'><a rel="contents" title="Table of Contents"
href="contents.html"><img src='../icons/contents.png'
border='0' height='32' alt='Contents' width='32' /></A></td>
<td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png'
border='0' height='32' alt='Module Index' width='32' /></a></td>
<td class='online-navigation'><a rel="index" title="Index"
href="genindex.html"><img src='../icons/index.png'
border='0' height='32' alt='Index' width='32' /></A></td>
</tr></table>
<div class='online-navigation'>
<b class="navlabel">Previous:</b>
<a class="sectref" rel="prev" href="module-inspect.html">3.11 inspect </A>
<b class="navlabel">Up:</b>
<a class="sectref" rel="parent" href="module-inspect.html">3.11 inspect </A>
<b class="navlabel">Next:</b>
<a class="sectref" rel="next" href="inspect-source.html">3.11.2 Retrieving source code</A>
</div>
</div>
<hr />
<span class="release-info">Release 2.4.2, documentation updated on 28 September 2005.</span>
</DIV>
<!--End of Navigation Panel-->
<ADDRESS>
See <i><a href="about.html">About this document...</a></i> for information on suggesting changes.
</ADDRESS>
</BODY>
</HTML>