| 1 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> |
| 2 | <html> |
| 3 | <head> |
| 4 | <link rel="STYLESHEET" href="api.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="api.html" title='Python/C API Reference Manual' /> |
| 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="moduleObjects.html" /> |
| 13 | <link rel="prev" href="instanceObjects.html" /> |
| 14 | <link rel="parent" href="otherObjects.html" /> |
| 15 | <link rel="next" href="moduleObjects.html" /> |
| 16 | <meta name='aesop' content='information' /> |
| 17 | <title>7.5.3 Method Objects </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="7.5.2 Instance Objects" |
| 25 | href="instanceObjects.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="7.5 Other Objects" |
| 28 | href="otherObjects.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="7.5.4 Module Objects" |
| 31 | href="moduleObjects.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/C API Reference Manual</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'><img src='../icons/blank.png' |
| 38 | border='0' height='32' alt='' width='32' /></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="instanceObjects.html">7.5.2 Instance Objects</A> |
| 46 | <b class="navlabel">Up:</b> |
| 47 | <a class="sectref" rel="parent" href="otherObjects.html">7.5 Other Objects</A> |
| 48 | <b class="navlabel">Next:</b> |
| 49 | <a class="sectref" rel="next" href="moduleObjects.html">7.5.4 Module Objects</A> |
| 50 | </div> |
| 51 | <hr /></div> |
| 52 | </DIV> |
| 53 | <!--End of Navigation Panel--> |
| 54 | |
| 55 | <H2><A NAME="SECTION009530000000000000000"></A><A NAME="method-objects"></A> |
| 56 | <BR> |
| 57 | 7.5.3 Method Objects |
| 58 | </H2> |
| 59 | |
| 60 | <P> |
| 61 | <a id='l2h-660' xml:id='l2h-660'></a>There are some useful functions that are useful for working with |
| 62 | method objects. |
| 63 | |
| 64 | <P> |
| 65 | <dl><dt>PyTypeObject <b><tt id='l2h-661' xml:id='l2h-661' class="cdata">PyMethod_Type</tt></b></dt> |
| 66 | <dd> |
| 67 | This instance of <tt class="ctype">PyTypeObject</tt> represents the Python method |
| 68 | type. This is exposed to Python programs as <code>types.MethodType</code>. |
| 69 | <a id='l2h-663' xml:id='l2h-663'></a></dd></dl> |
| 70 | |
| 71 | <P> |
| 72 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>int <b><tt id='l2h-664' xml:id='l2h-664' class="cfunction">PyMethod_Check</tt></b>(</nobr></td><td>PyObject *<var>o</var>)</td></tr></table></dt> |
| 73 | <dd> |
| 74 | Return true if <var>o</var> is a method object (has type |
| 75 | <tt class="cdata">PyMethod_Type</tt>). The parameter must not be <tt class="constant">NULL</tt>. |
| 76 | </dd></dl> |
| 77 | |
| 78 | <P> |
| 79 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>PyObject* <b><tt id='l2h-665' xml:id='l2h-665' class="cfunction">PyMethod_New</tt></b>(</nobr></td><td>PyObject *func. |
| 80 | PyObject *<var>self</var>, PyObject *<var>class</var>)</td></tr></table></dt> |
| 81 | <dd> |
| 82 | <div class="refcount-info"> |
| 83 | <span class="label">Return value:</span> |
| 84 | <span class="value">New reference.</span> |
| 85 | </div> |
| 86 | Return a new method object, with <var>func</var> being any callable |
| 87 | object; this is the function that will be called when the method is |
| 88 | called. If this method should be bound to an instance, <var>self</var> |
| 89 | should be the instance and <var>class</var> should be the class of |
| 90 | <var>self</var>, otherwise <var>self</var> should be <tt class="constant">NULL</tt> and <var>class</var> |
| 91 | should be the class which provides the unbound method.. |
| 92 | </dd></dl> |
| 93 | |
| 94 | <P> |
| 95 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>PyObject* <b><tt id='l2h-666' xml:id='l2h-666' class="cfunction">PyMethod_Class</tt></b>(</nobr></td><td>PyObject *<var>meth</var>)</td></tr></table></dt> |
| 96 | <dd> |
| 97 | <div class="refcount-info"> |
| 98 | <span class="label">Return value:</span> |
| 99 | <span class="value">Borrowed reference.</span> |
| 100 | </div> |
| 101 | Return the class object from which the method <var>meth</var> was |
| 102 | created; if this was created from an instance, it will be the class |
| 103 | of the instance. |
| 104 | </dd></dl> |
| 105 | |
| 106 | <P> |
| 107 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>PyObject* <b><tt id='l2h-667' xml:id='l2h-667' class="cfunction">PyMethod_GET_CLASS</tt></b>(</nobr></td><td>PyObject *<var>meth</var>)</td></tr></table></dt> |
| 108 | <dd> |
| 109 | <div class="refcount-info"> |
| 110 | <span class="label">Return value:</span> |
| 111 | <span class="value">Borrowed reference.</span> |
| 112 | </div> |
| 113 | Macro version of <tt class="cfunction">PyMethod_Class()</tt> which avoids error |
| 114 | checking. |
| 115 | </dd></dl> |
| 116 | |
| 117 | <P> |
| 118 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>PyObject* <b><tt id='l2h-668' xml:id='l2h-668' class="cfunction">PyMethod_Function</tt></b>(</nobr></td><td>PyObject *<var>meth</var>)</td></tr></table></dt> |
| 119 | <dd> |
| 120 | <div class="refcount-info"> |
| 121 | <span class="label">Return value:</span> |
| 122 | <span class="value">Borrowed reference.</span> |
| 123 | </div> |
| 124 | Return the function object associated with the method <var>meth</var>. |
| 125 | </dd></dl> |
| 126 | |
| 127 | <P> |
| 128 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>PyObject* <b><tt id='l2h-669' xml:id='l2h-669' class="cfunction">PyMethod_GET_FUNCTION</tt></b>(</nobr></td><td>PyObject *<var>meth</var>)</td></tr></table></dt> |
| 129 | <dd> |
| 130 | <div class="refcount-info"> |
| 131 | <span class="label">Return value:</span> |
| 132 | <span class="value">Borrowed reference.</span> |
| 133 | </div> |
| 134 | Macro version of <tt class="cfunction">PyMethod_Function()</tt> which avoids error |
| 135 | checking. |
| 136 | </dd></dl> |
| 137 | |
| 138 | <P> |
| 139 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>PyObject* <b><tt id='l2h-670' xml:id='l2h-670' class="cfunction">PyMethod_Self</tt></b>(</nobr></td><td>PyObject *<var>meth</var>)</td></tr></table></dt> |
| 140 | <dd> |
| 141 | <div class="refcount-info"> |
| 142 | <span class="label">Return value:</span> |
| 143 | <span class="value">Borrowed reference.</span> |
| 144 | </div> |
| 145 | Return the instance associated with the method <var>meth</var> if it is |
| 146 | bound, otherwise return <tt class="constant">NULL</tt>. |
| 147 | </dd></dl> |
| 148 | |
| 149 | <P> |
| 150 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>PyObject* <b><tt id='l2h-671' xml:id='l2h-671' class="cfunction">PyMethod_GET_SELF</tt></b>(</nobr></td><td>PyObject *<var>meth</var>)</td></tr></table></dt> |
| 151 | <dd> |
| 152 | <div class="refcount-info"> |
| 153 | <span class="label">Return value:</span> |
| 154 | <span class="value">Borrowed reference.</span> |
| 155 | </div> |
| 156 | Macro version of <tt class="cfunction">PyMethod_Self()</tt> which avoids error |
| 157 | checking. |
| 158 | </dd></dl> |
| 159 | |
| 160 | <P> |
| 161 | |
| 162 | <DIV CLASS="navigation"> |
| 163 | <div class='online-navigation'> |
| 164 | <p></p><hr /> |
| 165 | <table align="center" width="100%" cellpadding="0" cellspacing="2"> |
| 166 | <tr> |
| 167 | <td class='online-navigation'><a rel="prev" title="7.5.2 Instance Objects" |
| 168 | href="instanceObjects.html"><img src='../icons/previous.png' |
| 169 | border='0' height='32' alt='Previous Page' width='32' /></A></td> |
| 170 | <td class='online-navigation'><a rel="parent" title="7.5 Other Objects" |
| 171 | href="otherObjects.html"><img src='../icons/up.png' |
| 172 | border='0' height='32' alt='Up One Level' width='32' /></A></td> |
| 173 | <td class='online-navigation'><a rel="next" title="7.5.4 Module Objects" |
| 174 | href="moduleObjects.html"><img src='../icons/next.png' |
| 175 | border='0' height='32' alt='Next Page' width='32' /></A></td> |
| 176 | <td align="center" width="100%">Python/C API Reference Manual</td> |
| 177 | <td class='online-navigation'><a rel="contents" title="Table of Contents" |
| 178 | href="contents.html"><img src='../icons/contents.png' |
| 179 | border='0' height='32' alt='Contents' width='32' /></A></td> |
| 180 | <td class='online-navigation'><img src='../icons/blank.png' |
| 181 | border='0' height='32' alt='' width='32' /></td> |
| 182 | <td class='online-navigation'><a rel="index" title="Index" |
| 183 | href="genindex.html"><img src='../icons/index.png' |
| 184 | border='0' height='32' alt='Index' width='32' /></A></td> |
| 185 | </tr></table> |
| 186 | <div class='online-navigation'> |
| 187 | <b class="navlabel">Previous:</b> |
| 188 | <a class="sectref" rel="prev" href="instanceObjects.html">7.5.2 Instance Objects</A> |
| 189 | <b class="navlabel">Up:</b> |
| 190 | <a class="sectref" rel="parent" href="otherObjects.html">7.5 Other Objects</A> |
| 191 | <b class="navlabel">Next:</b> |
| 192 | <a class="sectref" rel="next" href="moduleObjects.html">7.5.4 Module Objects</A> |
| 193 | </div> |
| 194 | </div> |
| 195 | <hr /> |
| 196 | <span class="release-info">Release 2.4.2, documentation updated on 28 September 2005.</span> |
| 197 | </DIV> |
| 198 | <!--End of Navigation Panel--> |
| 199 | <ADDRESS> |
| 200 | See <i><a href="about.html">About this document...</a></i> for information on suggesting changes. |
| 201 | </ADDRESS> |
| 202 | </BODY> |
| 203 | </HTML> |