| 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="iterator.html" /> |
| 13 | <link rel="prev" href="sequence.html" /> |
| 14 | <link rel="parent" href="abstract.html" /> |
| 15 | <link rel="next" href="iterator.html" /> |
| 16 | <meta name='aesop' content='information' /> |
| 17 | <title>6.4 Mapping Protocol </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="6.3 Sequence Protocol" |
| 25 | href="sequence.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="6. Abstract Objects Layer" |
| 28 | href="abstract.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="6.5 Iterator Protocol" |
| 31 | href="iterator.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="sequence.html">6.3 Sequence Protocol</A> |
| 46 | <b class="navlabel">Up:</b> |
| 47 | <a class="sectref" rel="parent" href="abstract.html">6. Abstract Objects Layer</A> |
| 48 | <b class="navlabel">Next:</b> |
| 49 | <a class="sectref" rel="next" href="iterator.html">6.5 Iterator Protocol</A> |
| 50 | </div> |
| 51 | <hr /></div> |
| 52 | </DIV> |
| 53 | <!--End of Navigation Panel--> |
| 54 | |
| 55 | <H1><A NAME="SECTION008400000000000000000"></A><A NAME="mapping"></A> |
| 56 | <BR> |
| 57 | 6.4 Mapping Protocol |
| 58 | </H1> |
| 59 | |
| 60 | <P> |
| 61 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>int <b><tt id='l2h-334' xml:id='l2h-334' class="cfunction">PyMapping_Check</tt></b>(</nobr></td><td>PyObject *<var>o</var>)</td></tr></table></dt> |
| 62 | <dd> |
| 63 | Return <code>1</code> if the object provides mapping protocol, and |
| 64 | <code>0</code> otherwise. This function always succeeds. |
| 65 | </dd></dl> |
| 66 | |
| 67 | <P> |
| 68 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>int <b><tt id='l2h-335' xml:id='l2h-335' class="cfunction">PyMapping_Length</tt></b>(</nobr></td><td>PyObject *<var>o</var>)</td></tr></table></dt> |
| 69 | <dd> |
| 70 | Returns the number of keys in object <var>o</var> on success, and |
| 71 | <code>-1</code> on failure. For objects that do not provide mapping |
| 72 | protocol, this is equivalent to the Python expression |
| 73 | "<tt class="samp">len(<var>o</var>)</tt>".<a id='l2h-336' xml:id='l2h-336'></a></dd></dl> |
| 74 | |
| 75 | <P> |
| 76 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>int <b><tt id='l2h-337' xml:id='l2h-337' class="cfunction">PyMapping_DelItemString</tt></b>(</nobr></td><td>PyObject *<var>o</var>, char *<var>key</var>)</td></tr></table></dt> |
| 77 | <dd> |
| 78 | Remove the mapping for object <var>key</var> from the object <var>o</var>. |
| 79 | Return <code>-1</code> on failure. This is equivalent to the Python |
| 80 | statement "<tt class="samp">del <var>o</var>[<var>key</var>]</tt>". |
| 81 | </dd></dl> |
| 82 | |
| 83 | <P> |
| 84 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>int <b><tt id='l2h-338' xml:id='l2h-338' class="cfunction">PyMapping_DelItem</tt></b>(</nobr></td><td>PyObject *<var>o</var>, PyObject *<var>key</var>)</td></tr></table></dt> |
| 85 | <dd> |
| 86 | Remove the mapping for object <var>key</var> from the object <var>o</var>. |
| 87 | Return <code>-1</code> on failure. This is equivalent to the Python |
| 88 | statement "<tt class="samp">del <var>o</var>[<var>key</var>]</tt>". |
| 89 | </dd></dl> |
| 90 | |
| 91 | <P> |
| 92 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>int <b><tt id='l2h-339' xml:id='l2h-339' class="cfunction">PyMapping_HasKeyString</tt></b>(</nobr></td><td>PyObject *<var>o</var>, char *<var>key</var>)</td></tr></table></dt> |
| 93 | <dd> |
| 94 | On success, return <code>1</code> if the mapping object has the key |
| 95 | <var>key</var> and <code>0</code> otherwise. This is equivalent to the Python |
| 96 | expression "<tt class="samp"><var>o</var>.has_key(<var>key</var>)</tt>". This function always |
| 97 | succeeds. |
| 98 | </dd></dl> |
| 99 | |
| 100 | <P> |
| 101 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>int <b><tt id='l2h-340' xml:id='l2h-340' class="cfunction">PyMapping_HasKey</tt></b>(</nobr></td><td>PyObject *<var>o</var>, PyObject *<var>key</var>)</td></tr></table></dt> |
| 102 | <dd> |
| 103 | Return <code>1</code> if the mapping object has the key <var>key</var> and |
| 104 | <code>0</code> otherwise. This is equivalent to the Python expression |
| 105 | "<tt class="samp"><var>o</var>.has_key(<var>key</var>)</tt>". This function always succeeds. |
| 106 | </dd></dl> |
| 107 | |
| 108 | <P> |
| 109 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>PyObject* <b><tt id='l2h-341' xml:id='l2h-341' class="cfunction">PyMapping_Keys</tt></b>(</nobr></td><td>PyObject *<var>o</var>)</td></tr></table></dt> |
| 110 | <dd> |
| 111 | <div class="refcount-info"> |
| 112 | <span class="label">Return value:</span> |
| 113 | <span class="value">New reference.</span> |
| 114 | </div> |
| 115 | On success, return a list of the keys in object <var>o</var>. On |
| 116 | failure, return <tt class="constant">NULL</tt>. This is equivalent to the Python expression |
| 117 | "<tt class="samp"><var>o</var>.keys()</tt>". |
| 118 | </dd></dl> |
| 119 | |
| 120 | <P> |
| 121 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>PyObject* <b><tt id='l2h-342' xml:id='l2h-342' class="cfunction">PyMapping_Values</tt></b>(</nobr></td><td>PyObject *<var>o</var>)</td></tr></table></dt> |
| 122 | <dd> |
| 123 | <div class="refcount-info"> |
| 124 | <span class="label">Return value:</span> |
| 125 | <span class="value">New reference.</span> |
| 126 | </div> |
| 127 | On success, return a list of the values in object <var>o</var>. On |
| 128 | failure, return <tt class="constant">NULL</tt>. This is equivalent to the Python expression |
| 129 | "<tt class="samp"><var>o</var>.values()</tt>". |
| 130 | </dd></dl> |
| 131 | |
| 132 | <P> |
| 133 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>PyObject* <b><tt id='l2h-343' xml:id='l2h-343' class="cfunction">PyMapping_Items</tt></b>(</nobr></td><td>PyObject *<var>o</var>)</td></tr></table></dt> |
| 134 | <dd> |
| 135 | <div class="refcount-info"> |
| 136 | <span class="label">Return value:</span> |
| 137 | <span class="value">New reference.</span> |
| 138 | </div> |
| 139 | On success, return a list of the items in object <var>o</var>, where each |
| 140 | item is a tuple containing a key-value pair. On failure, return |
| 141 | <tt class="constant">NULL</tt>. This is equivalent to the Python expression |
| 142 | "<tt class="samp"><var>o</var>.items()</tt>". |
| 143 | </dd></dl> |
| 144 | |
| 145 | <P> |
| 146 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>PyObject* <b><tt id='l2h-344' xml:id='l2h-344' class="cfunction">PyMapping_GetItemString</tt></b>(</nobr></td><td>PyObject *<var>o</var>, char *<var>key</var>)</td></tr></table></dt> |
| 147 | <dd> |
| 148 | <div class="refcount-info"> |
| 149 | <span class="label">Return value:</span> |
| 150 | <span class="value">New reference.</span> |
| 151 | </div> |
| 152 | Return element of <var>o</var> corresponding to the object <var>key</var> or |
| 153 | <tt class="constant">NULL</tt> on failure. This is the equivalent of the Python expression |
| 154 | "<tt class="samp"><var>o</var>[<var>key</var>]</tt>". |
| 155 | </dd></dl> |
| 156 | |
| 157 | <P> |
| 158 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>int <b><tt id='l2h-345' xml:id='l2h-345' class="cfunction">PyMapping_SetItemString</tt></b>(</nobr></td><td>PyObject *<var>o</var>, char *<var>key</var>, |
| 159 | PyObject *<var>v</var>)</td></tr></table></dt> |
| 160 | <dd> |
| 161 | Map the object <var>key</var> to the value <var>v</var> in object <var>o</var>. |
| 162 | Returns <code>-1</code> on failure. This is the equivalent of the Python |
| 163 | statement "<tt class="samp"><var>o</var>[<var>key</var>] = <var>v</var></tt>". |
| 164 | </dd></dl> |
| 165 | |
| 166 | <P> |
| 167 | |
| 168 | <DIV CLASS="navigation"> |
| 169 | <div class='online-navigation'> |
| 170 | <p></p><hr /> |
| 171 | <table align="center" width="100%" cellpadding="0" cellspacing="2"> |
| 172 | <tr> |
| 173 | <td class='online-navigation'><a rel="prev" title="6.3 Sequence Protocol" |
| 174 | href="sequence.html"><img src='../icons/previous.png' |
| 175 | border='0' height='32' alt='Previous Page' width='32' /></A></td> |
| 176 | <td class='online-navigation'><a rel="parent" title="6. Abstract Objects Layer" |
| 177 | href="abstract.html"><img src='../icons/up.png' |
| 178 | border='0' height='32' alt='Up One Level' width='32' /></A></td> |
| 179 | <td class='online-navigation'><a rel="next" title="6.5 Iterator Protocol" |
| 180 | href="iterator.html"><img src='../icons/next.png' |
| 181 | border='0' height='32' alt='Next Page' width='32' /></A></td> |
| 182 | <td align="center" width="100%">Python/C API Reference Manual</td> |
| 183 | <td class='online-navigation'><a rel="contents" title="Table of Contents" |
| 184 | href="contents.html"><img src='../icons/contents.png' |
| 185 | border='0' height='32' alt='Contents' width='32' /></A></td> |
| 186 | <td class='online-navigation'><img src='../icons/blank.png' |
| 187 | border='0' height='32' alt='' width='32' /></td> |
| 188 | <td class='online-navigation'><a rel="index" title="Index" |
| 189 | href="genindex.html"><img src='../icons/index.png' |
| 190 | border='0' height='32' alt='Index' width='32' /></A></td> |
| 191 | </tr></table> |
| 192 | <div class='online-navigation'> |
| 193 | <b class="navlabel">Previous:</b> |
| 194 | <a class="sectref" rel="prev" href="sequence.html">6.3 Sequence Protocol</A> |
| 195 | <b class="navlabel">Up:</b> |
| 196 | <a class="sectref" rel="parent" href="abstract.html">6. Abstract Objects Layer</A> |
| 197 | <b class="navlabel">Next:</b> |
| 198 | <a class="sectref" rel="next" href="iterator.html">6.5 Iterator Protocol</A> |
| 199 | </div> |
| 200 | </div> |
| 201 | <hr /> |
| 202 | <span class="release-info">Release 2.4.2, documentation updated on 28 September 2005.</span> |
| 203 | </DIV> |
| 204 | <!--End of Navigation Panel--> |
| 205 | <ADDRESS> |
| 206 | See <i><a href="about.html">About this document...</a></i> for information on suggesting changes. |
| 207 | </ADDRESS> |
| 208 | </BODY> |
| 209 | </HTML> |