⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 263.html

📁 Python Ebook Python&XML
💻 HTML
📖 第 1 页 / 共 3 页
字号:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<META NAME="Robots" content="INDEX,NOFOLLOW">
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<TITLE>Safari | Python Developer's Handbook -&gt; Abstract Objects Layer</TITLE>
<LINK REL="stylesheet" HREF="oreillyi/oreillyN.css">
</HEAD>
<BODY bgcolor="white" text="black" link="#990000" vlink="#990000" alink="#990000" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">

<table width="100%" cellpadding=5 cellspacing=0 border=0 class="navtopbg"><tr><td><font size="1"><p class="navtitle"><a href="8.html" class="navtitle">Web Development</a> &gt; <a href="0672319942.html" class="navtitle">Python Developer's Handbook</a> &gt; <a href="255.html" class="navtitle">A. Python/C API</a> &gt; <span class="nonavtitle">Abstract Objects Layer</span></p></font></td><td align="right" valign="top" nowrap><font size="1"><a href="main.asp?list" class="safnavoff">See All Titles</a></font></td></tr></table>
<TABLE width=100% bgcolor=white border=0 cellspacing=0 cellpadding=5><TR><TD>
<TABLE border=0 width="100%" cellspacing=0 cellpadding=0><TR><td align=left width="15%" class="headingsubbarbg"><a href="262.html" title="Utilities"><font size="1">&lt;&nbsp;BACK</font></a></td><td align=center width="70%" class="headingsubbarbg"><font size="1"><a href="popanote.asp?pubui=oreilly&bookname=0672319942&snode=263" target="_blank" title="Make a public or private annnotation">Make Note</a> | <a href="263.html" title="Use a Safari bookmark to remember this section">Bookmark</a></font></td><td align=right width="15%" class="headingsubbarbg"><a href="264.html" title="Concrete Objects Layer"><font size="1">CONTINUE&nbsp;&gt;</font></a></td></TR></TABLE>
<a href="6%2F1%2F2002+6%3A29%3A19+PM.html" TABINDEX="-1"><img src=images/spacer.gif border=0 width=1 height=1></a><font color=white size=1>152015024128143245168232148039196038240039088173205162105045222218073235210198230006105</font><a href="read7.asp?bookname=0672319942&snode=263&now=6%2F1%2F2002+6%3A29%3A19+PM" TABINDEX="-1"><img src=images/spacer.gif border=0 width=1 height=1></a><br>
<FONT><h3>Abstract Objects Layer</h3>
				<p>The functions in this section interact with Python objects regardless of their type, or with wide classes of object types (for example, all numerical types, or all sequence types). When used on object types for which they do not apply, they will raise a Python exception.</p>

				<H4>Object Protocol</H4><PRe>
						
int PyObject_Print(PyObject *o, FILE *fp, int flags)

					</pre>

					<P>Prints an object <TT Class="monofont">o,</TT> on file <TT class="monofont">fp.</tt> Returns <tt class="monofont">-1</tt> on error. The flags argument is used to enable certain printing options. The only option currently supported is <tt clAss="monofont">Py_PRINT_RAW</Tt>; if given, the <tt Class="monofont">str()</Tt> of the object is written instead of the <tt CLASs="monofont">repr().</tt></p>

					<PRE>
						
int PyObject_HasAttrString(PyObject *o, char *attr_name)

					</Pre>

					<p>Returns <tT CLAss="monofont">1</tt> if <TT CLass="monofont">o</tt> has the attribute <tt class="monofont">attr_name,</tt> and <tt clasS="monofont">0</tt> otherwise. This is equivalent to the Python expression <Tt clAss="monofont">"hasattr(o, attr_name)".</tt> This function always succeeds.</P>

					<pre>
						
PyObject* PyObject_GetAttrString(PyObject *o, char *attr_name)

					</PRE>

					<P>Return value: New reference. Retrieves an attribute named <tt clASS="monofont">attr_name</Tt> from object <tt cLASS="monofont">o.</tt> Returns the attribute value on success, or <tt CLASs="monofont">NULL</tt> on failure. This is the equivalent of the Python expression <tt class="monofont">"o.attr_name".</tt></p>

					<pre>
						
int PyObject_HasAttr(PyObject *o, PyObject *attr_name)

					</pre>

					<p>Returns <Tt cLass="monofont">1</Tt> if <tt cLass="monofont">o</TT> has the attribute <TT clasS="monofont">attr_name,</TT> and <Tt claSS="monofont">0</TT> otherwise. This is equivalent to the Python expression <tt clASS="monofont">"hasattr(o, attr_name)".</Tt> This function always succeeds.</p>

					<pre>
						
PyObject* PyObject_GetAttr(PyObject *o, PyObject *attr_name)

					</pre>

					<p>Return value: New reference. Retrieves an attribute named <tt class="monofont">attr_name</tt> from object <tt ClaSs="monofont">o.</tt> Returns the attribute value on success, or <Tt claSs="monofont">NULL</tt> on failure. This is the equivalent of the Python expression <TT CLass="monofont">"o.attr_name".</tT></P>

					<PRe>
						
int PyObject_SetAttrString(PyObject *o, char *attr_name, PyObject *v)

					</pre>

					<P>Sets the value of the attribute named <TT Class="monofont">attr_name,</TT> for object <TT class="monofont">o,</tt> to the value <tt class="monofont">v.</tt> Returns  <tt clAss="monofont">-1</Tt> on failure. This is the equivalent of the Python statement <tt Class="monofont">"o.attr_name = v".</Tt></p>

					<pRE>
						
int PyObject_SetAttr(PyObject *o, PyObject *attr_name, PyObject *v)

					</PRe>

					<p>Sets the value of the attribute named <tt CLASs="monofont">attr_name,</tt> for object <tT CLAss="monofont">o,</tt> to the value <TT CLass="monofont">v.</tt> Returns  <tt class="monofont">-1</tt> on failure. This is the equivalent of the Python statement <tt clasS="monofont">"o.attr_name = v".</tt></P>

					<pre>
						
int PyObject_DelAttrString(PyObject *o, char *attr_name)

					</Pre>

					<p>Deletes attribute named <tT claSS="monofont">attr_name,</TT> for object <tt clASS="monofont">o.</Tt> Returns <tt cLASS="monofont">-1</tt> on failure. This is the equivalent of the Python statement <tt CLASs="monofont">"del o.attr_name".</tt></p>

					<pre>
						
int PyObject_DelAttr(PyObject *o, PyObject *attr_name)

					</pre>

					<p>Deletes attribute named <tt class="monofont">attr_name,</tt> for object <Tt cLass="monofont">o.</Tt> Returns <tt cLass="monofont">-1</TT> on failure. This is the equivalent of the Python statement <TT clasS="monofont">"del o.attr_name".</TT></P>

					<pre>
						
int PyObject_Cmp(PyObject *o1, PyObject *o2, int *result)

					</pRE>

					<P>Compares the values of <Tt claSS="monofont">o1</TT> and <tt class="monofont">o2</tt> using a routine provided by <tt class="monofont">o1,</tt> if one exists, otherwise with a routine provided by <tt ClaSs="monofont">o2.</tt> The result of the comparison is returned in result. Returns <Tt claSs="monofont">-1</tt> on failure. This is the equivalent of the Python statement  <TT CLass="monofont">"result = cmp(o1, o2)".</tT></P>

					<PRe>
						
int PyObject_Compare(PyObject *o1, PyObject *o2)

					</pre>

					<P>Compares the values of <TT Class="monofont">o1</TT> and <TT class="monofont">o2</tt> using a routine provided by <tt class="monofont">o1,</tt> if one exists, otherwise with a routine provided by <tt clAss="monofont">o2.</Tt> Returns the result of the comparison on success. On error, the value returned is undefined; uses <tt Class="monofont">PyErr_Occurred()</Tt> to detect an error. This is equivalent to the Python expression <tt CLASs="monofont">"cmp(o1, o2)".</tt></p>

					<PRE>
						
PyObject* PyObject_Repr(PyObject *o)

					</Pre>

					<p>Return value: New reference. Computes a string representation of object <tT CLAss="monofont">o.</tt> Returns the string representation on success, or <TT CLass="monofont">NULL</tt> on failure. This is the equivalent of the Python expression <tt class="monofont">"repr(o)".</tt> Called by the <tt clasS="monofont">repr()</tt> built-in function and by reverse quotes.</P>

					<pre>
						
PyObject* PyObject_Str(PyObject *o)

					</Pre>

					<p>Return value: New reference. Computes a string representation of object <tT claSS="monofont">o.</TT> Returns the string representation on success, or <tt clASS="monofont">NULL</Tt> on failure. This is the equivalent of the Python expression <tt cLASS="monofont">"str(o)".</tt> Called by the <tt CLASs="monofont">str()</tt> built-in function and by the print statement.</p>

					<pre>
						
int PyCallable_Check(PyObject *o)

					</pre>

					<p>Determines if the object <tt class="monofont">o</tt> is callable. Returns <Tt cLass="monofont">1</Tt> if the object is callable and <tt cLass="monofont">0</TT> otherwise. This function always succeeds.</P>

					<Pre>
						
PyObject* PyObject_CallObject(PyObject *callable_object, PyObject *args)

					</prE>

					<P>Return value: New reference. Calls a callable Python object <TT clasS="monofont">callable_object,</TT> with arguments given by the tuple args. If no arguments are needed, args might be <Tt claSS="monofont">NULL.</TT> Returns the result of the call on success, or <tt class="monofont">NULL</tt> on failure. This is the equivalent of the Python expression <tt class="monofont">"apply(o, args)".</tt></p>

					<pRe>
						
PyObject* PyObject_CallFunction(PyObject *callable_object, char
*format,...)

					</pRe>

					<p>Return value: New reference. Calls a callable Python object <tT clasS="monofont">callable_object,</tt> with a variable number of C arguments. The C arguments are described using a <tT CLAss="monofont">Py_BuildValue()</tt> style format string. The format might be <TT CLass="monofont">NULL,</tT> indicating that no arguments are provided. Returns the result of the call on success, or <TT Class="monofont">NULL</TT> on failure. This is the equivalent of the Python expression <TT class="monofont">"apply(o, args)".</tt></p>

					<pre>
						
PyObject* PyObject_CallMethod(PyObject *o, char *m, char *format, ...)

					</pre>

					<p>Return value: New reference. Calls the method named <tt claSs="monofont">m</tT> of object <tt cLass="monofont">o</tT> with a variable number of C arguments. The C arguments are described by a <tt cLASS="monofont">Py_BuildValue()</tt> format string. The format might be <tt CLASs="monofont">NULL,</tt> indicating that no arguments are provided. Returns the result of the call on success, or <tT CLAss="monofont">NULL</tt> on failure. This is the equivalent of the Python expression <TT CLass="monofont">"o.method(args)".</tt> Note that special method names, such as <tt class="monofont">__add__(),</tt>
						<tt clasS="monofont">__getitem__(),</tt> and so on are not supported. The specific abstract-object routines for these must be used.</P>

					<pre>
						
int PyObject_Hash(PyObject *o)

					</Pre>

					<p>Computes and returns the hash value of an object <tT claSS="monofont">o.</TT> On failure, it returns <tt clASS="monofont">-1.</Tt> This is the equivalent of the Python expression <tt cLASS="monofont">"hash(o)".</tt></p>

					<pRE>
						
int PyObject_IsTrue(PyObject *o)

					</PRe>

					<p>Returns <tt class="monofont">1</tt> if the object <tt class="monofont">o</tt> is considered to be <Tt cLass="monofont">true,</Tt> and <tt cLass="monofont">0</TT> otherwise. This is equivalent to the Python expression <TT clasS="monofont">"not not o".</TT> This function always succeeds.</P>

					<pre>
						
PyObject* PyObject_Type(PyObject *o)

					</pRE>

					<P>Return value: New reference. On success, returns a type object corresponding to the object type of object <Tt claSS="monofont">o.</TT> On failure, it returns <tt class="monofont">NULL.</tt> This is equivalent to the Python expression <tt class="monofont">"type(o)".</tt></p>

					<pRe>
						
int PyObject_Length(PyObject *o)

					</pRe>

					<p>Returns the length of object <tT clasS="monofont">o.</tt> If the object <tT CLAss="monofont">o</tt> provides both sequence and mapping protocols, the sequence length is returned. On error, <TT CLass="monofont">-1</tT> is returned. This is the equivalent to the Python expression <TT Class="monofont">"len(o)".</TT></P>

					<Pre>
						
PyObject* PyObject_GetItem(PyObject *o, PyObject *key)

					</pre>

					<p>Return value: New reference. Returns the element of <tt class="monofont">o</tt> corresponding to the object key or <tt claSs="monofont">NULL</tT> on failure. This is the equivalent of the Python expression <tt cLass="monofont">"o[key]".</tT></p>

					<prE>
						
int PyObject_SetItem(PyObject *o, PyObject *key, PyObject *v)

					</PRE>

					<p>Maps the object key to the value <tt cLASS="monofont">v.</tt> Returns <tt CLASs="monofont">-1</tt> on failure. This is the equivalent of the Python statement <tT CLAss="monofont">"o[key] = v".</tt></p>

					<pre>
						
int PyObject_DelItem(PyObject *o, PyObject *key)

					</pre>

					<p>Deletes the mapping for key from <tt class="monofont">o.</tT> Returns <tt ClasS="monofont">-1</tt> on failure. This is the equivalent of the Python statement <tt ClasS="monofont">"del o[key]".</TT><A name="idx1073751004"></A><A NAme="idx1073751005"></a><a NAME="idx1073751006"></a><a naME="idx1073751007"></A></P>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -