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="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="floatObjects.html" /> | |
13 | <link rel="prev" href="boolObjects.html" /> | |
14 | <link rel="parent" href="numericObjects.html" /> | |
15 | <link rel="next" href="floatObjects.html" /> | |
16 | <meta name='aesop' content='information' /> | |
17 | <title>7.2.3 Long Integer 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.2.2 Boolean Objects" | |
25 | href="boolObjects.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.2 Numeric Objects" | |
28 | href="numericObjects.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.2.4 Floating Point Objects" | |
31 | href="floatObjects.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="boolObjects.html">7.2.2 Boolean Objects</A> | |
46 | <b class="navlabel">Up:</b> | |
47 | <a class="sectref" rel="parent" href="numericObjects.html">7.2 Numeric Objects</A> | |
48 | <b class="navlabel">Next:</b> | |
49 | <a class="sectref" rel="next" href="floatObjects.html">7.2.4 Floating Point Objects</A> | |
50 | </div> | |
51 | <hr /></div> | |
52 | </DIV> | |
53 | <!--End of Navigation Panel--> | |
54 | ||
55 | <H2><A NAME="SECTION009230000000000000000"></A><A NAME="longObjects"></A> | |
56 | <BR> | |
57 | 7.2.3 Long Integer Objects | |
58 | </H2> | |
59 | ||
60 | <P> | |
61 | <a id='l2h-390' xml:id='l2h-390'></a><dl><dt><b><tt class="ctype"><a id='l2h-391' xml:id='l2h-391'>PyLongObject</a></tt></b></dt> | |
62 | <dd> | |
63 | This subtype of <tt class="ctype">PyObject</tt> represents a Python long integer | |
64 | object. | |
65 | </dl> | |
66 | ||
67 | <P> | |
68 | <dl><dt>PyTypeObject <b><tt id='l2h-392' xml:id='l2h-392' class="cdata">PyLong_Type</tt></b></dt> | |
69 | <dd> | |
70 | This instance of <tt class="ctype">PyTypeObject</tt> represents the Python long | |
71 | integer type. This is the same object as <code>types.LongType</code>. | |
72 | <a id='l2h-394' xml:id='l2h-394'></a></dd></dl> | |
73 | ||
74 | <P> | |
75 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>int <b><tt id='l2h-395' xml:id='l2h-395' class="cfunction">PyLong_Check</tt></b>(</nobr></td><td>PyObject *<var>p</var>)</td></tr></table></dt> | |
76 | <dd> | |
77 | Return true if its argument is a <tt class="ctype">PyLongObject</tt> or a subtype | |
78 | of <tt class="ctype">PyLongObject</tt>. | |
79 | ||
80 | <span class="versionnote">Changed in version 2.2: | |
81 | Allowed subtypes to be accepted.</span> | |
82 | ||
83 | </dd></dl> | |
84 | ||
85 | <P> | |
86 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>int <b><tt id='l2h-396' xml:id='l2h-396' class="cfunction">PyLong_CheckExact</tt></b>(</nobr></td><td>PyObject *<var>p</var>)</td></tr></table></dt> | |
87 | <dd> | |
88 | Return true if its argument is a <tt class="ctype">PyLongObject</tt>, but not a | |
89 | subtype of <tt class="ctype">PyLongObject</tt>. | |
90 | ||
91 | <span class="versionnote">New in version 2.2.</span> | |
92 | ||
93 | </dd></dl> | |
94 | ||
95 | <P> | |
96 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>PyObject* <b><tt id='l2h-397' xml:id='l2h-397' class="cfunction">PyLong_FromLong</tt></b>(</nobr></td><td>long <var>v</var>)</td></tr></table></dt> | |
97 | <dd> | |
98 | <div class="refcount-info"> | |
99 | <span class="label">Return value:</span> | |
100 | <span class="value">New reference.</span> | |
101 | </div> | |
102 | Return a new <tt class="ctype">PyLongObject</tt> object from <var>v</var>, or <tt class="constant">NULL</tt> | |
103 | on failure. | |
104 | </dd></dl> | |
105 | ||
106 | <P> | |
107 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>PyObject* <b><tt id='l2h-398' xml:id='l2h-398' class="cfunction">PyLong_FromUnsignedLong</tt></b>(</nobr></td><td>unsigned long <var>v</var>)</td></tr></table></dt> | |
108 | <dd> | |
109 | <div class="refcount-info"> | |
110 | <span class="label">Return value:</span> | |
111 | <span class="value">New reference.</span> | |
112 | </div> | |
113 | Return a new <tt class="ctype">PyLongObject</tt> object from a C <tt class="ctype">unsigned | |
114 | long</tt>, or <tt class="constant">NULL</tt> on failure. | |
115 | </dd></dl> | |
116 | ||
117 | <P> | |
118 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>PyObject* <b><tt id='l2h-399' xml:id='l2h-399' class="cfunction">PyLong_FromLongLong</tt></b>(</nobr></td><td>long long <var>v</var>)</td></tr></table></dt> | |
119 | <dd> | |
120 | <div class="refcount-info"> | |
121 | <span class="label">Return value:</span> | |
122 | <span class="value">New reference.</span> | |
123 | </div> | |
124 | Return a new <tt class="ctype">PyLongObject</tt> object from a C <tt class="ctype">long long</tt>, | |
125 | or <tt class="constant">NULL</tt> on failure. | |
126 | </dd></dl> | |
127 | ||
128 | <P> | |
129 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>PyObject* <b><tt id='l2h-400' xml:id='l2h-400' class="cfunction">PyLong_FromUnsignedLongLong</tt></b>(</nobr></td><td>unsigned long long <var>v</var>)</td></tr></table></dt> | |
130 | <dd> | |
131 | <div class="refcount-info"> | |
132 | <span class="label">Return value:</span> | |
133 | <span class="value">New reference.</span> | |
134 | </div> | |
135 | Return a new <tt class="ctype">PyLongObject</tt> object from a C <tt class="ctype">unsigned | |
136 | long long</tt>, or <tt class="constant">NULL</tt> on failure. | |
137 | </dd></dl> | |
138 | ||
139 | <P> | |
140 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>PyObject* <b><tt id='l2h-401' xml:id='l2h-401' class="cfunction">PyLong_FromDouble</tt></b>(</nobr></td><td>double <var>v</var>)</td></tr></table></dt> | |
141 | <dd> | |
142 | <div class="refcount-info"> | |
143 | <span class="label">Return value:</span> | |
144 | <span class="value">New reference.</span> | |
145 | </div> | |
146 | Return a new <tt class="ctype">PyLongObject</tt> object from the integer part of | |
147 | <var>v</var>, or <tt class="constant">NULL</tt> on failure. | |
148 | </dd></dl> | |
149 | ||
150 | <P> | |
151 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>PyObject* <b><tt id='l2h-402' xml:id='l2h-402' class="cfunction">PyLong_FromString</tt></b>(</nobr></td><td>char *<var>str</var>, char **<var>pend</var>, | |
152 | int <var>base</var>)</td></tr></table></dt> | |
153 | <dd> | |
154 | <div class="refcount-info"> | |
155 | <span class="label">Return value:</span> | |
156 | <span class="value">New reference.</span> | |
157 | </div> | |
158 | Return a new <tt class="ctype">PyLongObject</tt> based on the string value in | |
159 | <var>str</var>, which is interpreted according to the radix in | |
160 | <var>base</var>. If <var>pend</var> is non-<tt class="constant">NULL</tt>, <code>*<var>pend</var></code> will | |
161 | point to the first character in <var>str</var> which follows the | |
162 | representation of the number. If <var>base</var> is <code>0</code>, the radix | |
163 | will be determined based on the leading characters of <var>str</var>: if | |
164 | <var>str</var> starts with <code>'0x'</code> or <code>'0X'</code>, radix 16 will be | |
165 | used; if <var>str</var> starts with <code>'0'</code>, radix 8 will be used; | |
166 | otherwise radix 10 will be used. If <var>base</var> is not <code>0</code>, it | |
167 | must be between <code>2</code> and <code>36</code>, inclusive. Leading spaces | |
168 | are ignored. If there are no digits, <tt class="exception">ValueError</tt> will be | |
169 | raised. | |
170 | </dd></dl> | |
171 | ||
172 | <P> | |
173 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>PyObject* <b><tt id='l2h-403' xml:id='l2h-403' class="cfunction">PyLong_FromUnicode</tt></b>(</nobr></td><td>Py_UNICODE *<var>u</var>, | |
174 | int <var>length</var>, int <var>base</var>)</td></tr></table></dt> | |
175 | <dd> | |
176 | <div class="refcount-info"> | |
177 | <span class="label">Return value:</span> | |
178 | <span class="value">New reference.</span> | |
179 | </div> | |
180 | Convert a sequence of Unicode digits to a Python long integer | |
181 | value. The first parameter, <var>u</var>, points to the first character | |
182 | of the Unicode string, <var>length</var> gives the number of characters, | |
183 | and <var>base</var> is the radix for the conversion. The radix must be | |
184 | in the range [2, 36]; if it is out of range, <tt class="exception">ValueError</tt> | |
185 | will be raised. | |
186 | ||
187 | <span class="versionnote">New in version 1.6.</span> | |
188 | ||
189 | </dd></dl> | |
190 | ||
191 | <P> | |
192 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>PyObject* <b><tt id='l2h-404' xml:id='l2h-404' class="cfunction">PyLong_FromVoidPtr</tt></b>(</nobr></td><td>void *<var>p</var>)</td></tr></table></dt> | |
193 | <dd> | |
194 | <div class="refcount-info"> | |
195 | <span class="label">Return value:</span> | |
196 | <span class="value">New reference.</span> | |
197 | </div> | |
198 | Create a Python integer or long integer from the pointer <var>p</var>. | |
199 | The pointer value can be retrieved from the resulting value using | |
200 | <tt class="cfunction">PyLong_AsVoidPtr()</tt>. | |
201 | ||
202 | <span class="versionnote">New in version 1.5.2.</span> | |
203 | ||
204 | </dd></dl> | |
205 | ||
206 | <P> | |
207 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>long <b><tt id='l2h-405' xml:id='l2h-405' class="cfunction">PyLong_AsLong</tt></b>(</nobr></td><td>PyObject *<var>pylong</var>)</td></tr></table></dt> | |
208 | <dd> | |
209 | Return a C <tt class="ctype">long</tt> representation of the contents of | |
210 | <var>pylong</var>. If <var>pylong</var> is greater than | |
211 | <tt class="constant">LONG_MAX</tt><a id='l2h-417' xml:id='l2h-417'></a>, an <tt class="exception">OverflowError</tt> | |
212 | is raised. | |
213 | <a id='l2h-407' xml:id='l2h-407'></a></dd></dl> | |
214 | ||
215 | <P> | |
216 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>unsigned long <b><tt id='l2h-408' xml:id='l2h-408' class="cfunction">PyLong_AsUnsignedLong</tt></b>(</nobr></td><td>PyObject *<var>pylong</var>)</td></tr></table></dt> | |
217 | <dd> | |
218 | Return a C <tt class="ctype">unsigned long</tt> representation of the contents of | |
219 | <var>pylong</var>. If <var>pylong</var> is greater than | |
220 | <tt class="constant">ULONG_MAX</tt><a id='l2h-418' xml:id='l2h-418'></a>, an | |
221 | <tt class="exception">OverflowError</tt> is raised. | |
222 | <a id='l2h-410' xml:id='l2h-410'></a></dd></dl> | |
223 | ||
224 | <P> | |
225 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>long long <b><tt id='l2h-411' xml:id='l2h-411' class="cfunction">PyLong_AsLongLong</tt></b>(</nobr></td><td>PyObject *<var>pylong</var>)</td></tr></table></dt> | |
226 | <dd> | |
227 | Return a C <tt class="ctype">long long</tt> from a Python long integer. If | |
228 | <var>pylong</var> cannot be represented as a <tt class="ctype">long long</tt>, an | |
229 | <tt class="exception">OverflowError</tt> will be raised. | |
230 | ||
231 | <span class="versionnote">New in version 2.2.</span> | |
232 | ||
233 | </dd></dl> | |
234 | ||
235 | <P> | |
236 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>unsigned long long <b><tt id='l2h-412' xml:id='l2h-412' class="cfunction">PyLong_AsUnsignedLongLong</tt></b>(</nobr></td><td>PyObject | |
237 | *<var>pylong</var>)</td></tr></table></dt> | |
238 | <dd> | |
239 | Return a C <tt class="ctype">unsigned long long</tt> from a Python long integer. | |
240 | If <var>pylong</var> cannot be represented as an <tt class="ctype">unsigned long | |
241 | long</tt>, an <tt class="exception">OverflowError</tt> will be raised if the value is | |
242 | positive, or a <tt class="exception">TypeError</tt> will be raised if the value is | |
243 | negative. | |
244 | ||
245 | <span class="versionnote">New in version 2.2.</span> | |
246 | ||
247 | </dd></dl> | |
248 | ||
249 | <P> | |
250 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>unsigned long <b><tt id='l2h-413' xml:id='l2h-413' class="cfunction">PyLong_AsUnsignedLongMask</tt></b>(</nobr></td><td>PyObject *<var>io</var>)</td></tr></table></dt> | |
251 | <dd> | |
252 | Return a C <tt class="ctype">unsigned long</tt> from a Python long integer, without | |
253 | checking for overflow. | |
254 | ||
255 | <span class="versionnote">New in version 2.3.</span> | |
256 | ||
257 | </dd></dl> | |
258 | ||
259 | <P> | |
260 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>unsigned long <b><tt id='l2h-414' xml:id='l2h-414' class="cfunction">PyLong_AsUnsignedLongLongMask</tt></b>(</nobr></td><td>PyObject *<var>io</var>)</td></tr></table></dt> | |
261 | <dd> | |
262 | Return a C <tt class="ctype">unsigned long long</tt> from a Python long integer, without | |
263 | checking for overflow. | |
264 | ||
265 | <span class="versionnote">New in version 2.3.</span> | |
266 | ||
267 | </dd></dl> | |
268 | ||
269 | <P> | |
270 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>double <b><tt id='l2h-415' xml:id='l2h-415' class="cfunction">PyLong_AsDouble</tt></b>(</nobr></td><td>PyObject *<var>pylong</var>)</td></tr></table></dt> | |
271 | <dd> | |
272 | Return a C <tt class="ctype">double</tt> representation of the contents of | |
273 | <var>pylong</var>. If <var>pylong</var> cannot be approximately represented | |
274 | as a <tt class="ctype">double</tt>, an <tt class="exception">OverflowError</tt> exception is | |
275 | raised and <code>-1.0</code> will be returned. | |
276 | </dd></dl> | |
277 | ||
278 | <P> | |
279 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>void* <b><tt id='l2h-416' xml:id='l2h-416' class="cfunction">PyLong_AsVoidPtr</tt></b>(</nobr></td><td>PyObject *<var>pylong</var>)</td></tr></table></dt> | |
280 | <dd> | |
281 | Convert a Python integer or long integer <var>pylong</var> to a C | |
282 | <tt class="ctype">void</tt> pointer. If <var>pylong</var> cannot be converted, an | |
283 | <tt class="exception">OverflowError</tt> will be raised. This is only assured to | |
284 | produce a usable <tt class="ctype">void</tt> pointer for values created with | |
285 | <tt class="cfunction">PyLong_FromVoidPtr()</tt>. | |
286 | ||
287 | <span class="versionnote">New in version 1.5.2.</span> | |
288 | ||
289 | </dd></dl> | |
290 | ||
291 | <P> | |
292 | ||
293 | <DIV CLASS="navigation"> | |
294 | <div class='online-navigation'> | |
295 | <p></p><hr /> | |
296 | <table align="center" width="100%" cellpadding="0" cellspacing="2"> | |
297 | <tr> | |
298 | <td class='online-navigation'><a rel="prev" title="7.2.2 Boolean Objects" | |
299 | href="boolObjects.html"><img src='../icons/previous.png' | |
300 | border='0' height='32' alt='Previous Page' width='32' /></A></td> | |
301 | <td class='online-navigation'><a rel="parent" title="7.2 Numeric Objects" | |
302 | href="numericObjects.html"><img src='../icons/up.png' | |
303 | border='0' height='32' alt='Up One Level' width='32' /></A></td> | |
304 | <td class='online-navigation'><a rel="next" title="7.2.4 Floating Point Objects" | |
305 | href="floatObjects.html"><img src='../icons/next.png' | |
306 | border='0' height='32' alt='Next Page' width='32' /></A></td> | |
307 | <td align="center" width="100%">Python/C API Reference Manual</td> | |
308 | <td class='online-navigation'><a rel="contents" title="Table of Contents" | |
309 | href="contents.html"><img src='../icons/contents.png' | |
310 | border='0' height='32' alt='Contents' width='32' /></A></td> | |
311 | <td class='online-navigation'><img src='../icons/blank.png' | |
312 | border='0' height='32' alt='' width='32' /></td> | |
313 | <td class='online-navigation'><a rel="index" title="Index" | |
314 | href="genindex.html"><img src='../icons/index.png' | |
315 | border='0' height='32' alt='Index' width='32' /></A></td> | |
316 | </tr></table> | |
317 | <div class='online-navigation'> | |
318 | <b class="navlabel">Previous:</b> | |
319 | <a class="sectref" rel="prev" href="boolObjects.html">7.2.2 Boolean Objects</A> | |
320 | <b class="navlabel">Up:</b> | |
321 | <a class="sectref" rel="parent" href="numericObjects.html">7.2 Numeric Objects</A> | |
322 | <b class="navlabel">Next:</b> | |
323 | <a class="sectref" rel="next" href="floatObjects.html">7.2.4 Floating Point Objects</A> | |
324 | </div> | |
325 | </div> | |
326 | <hr /> | |
327 | <span class="release-info">Release 2.4.2, documentation updated on 28 September 2005.</span> | |
328 | </DIV> | |
329 | <!--End of Navigation Panel--> | |
330 | <ADDRESS> | |
331 | See <i><a href="about.html">About this document...</a></i> for information on suggesting changes. | |
332 | </ADDRESS> | |
333 | </BODY> | |
334 | </HTML> |