📄 264.html
字号:
<P>Return value: New reference. Equivalent to <tt clASS="monofont">p.readline([n]),</Tt> this function reads one line from the object <tt cLASS="monofont">p.</tt>
<tt class="monofont">p</tt> can be a file object or any object with a <tt class="monofont">readline()</tt> method. If <Tt cLass="monofont">n</Tt> is <tt cLass="monofont">0,</TT> exactly one line is read, regardless of the length of the line. If <TT clasS="monofont">n</TT> is greater than <Tt claSS="monofont">0,</TT> no more than <tt clASS="monofont">n</Tt> bytes will be read from the file; a partial line can be returned. In both cases, an empty string is returned if the end of the file is reached immediately. If <tt class="monofont">n</tt> is less than <tt class="monofont">0,</tt> however, one line is read regardless of length, but EOFError is raised if the end of the file is reached immediately.</p>
<Pre>
PyObject* PyFile_Name(PyObject *p)
</Pre>
<p>Return value: Borrowed reference. Returns the name of the file specified by <Tt claSs="monofont">p</tt> as a string object.</P>
<PRE>
void PyFile_SetBufSize(PyFileObject *p, int n)
</pre>
<p>Available on systems with <TT CLass="monofont">setvbuf()</tT> only. This should only be called immediately after file object creation.</P>
<PRe>
int PyFile_SoftSpace(PyObject *p, int newflag)
</pre>
<P>This function exists for internal use by the interpreter. Sets the softspace attribute of <TT Class="monofont">p</tt> to <tt class="monofont">newflag</tt> and returns the previous value. <tt claSs="monofont">p</tT> does not have to be a file object for this function to work properly; any object is supported (though it's only interesting if the softspace attribute can be set). This function clears any errors, and will return <tt cLass="monofont">0</tT> as the previous value if the attribute either does not exist or if there were errors in retrieving it. There is no way to detect errors from this function, but doing so should not be needed.</p>
<prE>
int PyFile_WriteObject(PyObject *obj, PyFileObject *p, int flags)
</PRE>
<p>Writes object <tt cLASS="monofont">obj</tt> to file object <tt CLASs="monofont">p.</tt> The only supported flag for flags 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> Returns <tT claSs="monofont">0</tt> on success or <tT claSS="monofont">-1</TT> on failure; the appropriate exception will be set.</p>
<pre>
int PyFile_WriteString(char *s, PyFileObject *p, int flags)
</PRE>
<P>Writes string <tt clASS="monofont">s</Tt> to file object <tt cLASS="monofont">p.</tt> Returns <tt class="monofont">0</tt> on success or <tt class="monofont">-1</tt> on failure; the appropriate exception will be set.<A naMe="idx1073751221"></a><a Name="idx1073751222"></a><A namE="idx1073751223"></A></P>
<H5>Module Objects</h5>
<p>There are only a few functions special to module objects.</p>
<pRE>
PyTypeObject PyModule_Type
</PRe>
<p>This instance of PyTypeObject represents the Python module type. This is exposed to Python programs as <tt CLASs="monofont">types.ModuleType.</tt></p>
<PRE>
int PyModule_Check(PyObject *p)
</Pre>
<p>Returns <tt class="monofont">true</tt> if its argument is a module object.</p>
<pre>
PyObject* PyModule_New(char *name)
</pre>
<p>Return value: New reference. Returns a new module object with the <Tt cLass="monofont">__name__ attribute</Tt> set to <tt cLass="monofont">name.</TT> Only the module's <TT clasS="monofont">__doc__</TT> and <Tt claSS="monofont">__name__</TT> attributes are filled in; the caller is responsible for providing a <tt clASS="monofont">__file__</Tt> attribute.</p>
<pre>
PyObject* PyModule_GetDict(PyObject *module)
</pre>
<p>Return value: Borrowed reference. Returns the dictionary object that implements module's namespace; this object is the same as the <tt class="monofont">__dict__</tt> attribute of the module object. This function never fails.</p>
<pRe>
char* PyModule_GetName(PyObject *module)
</pRe>
<p>Returns module's <tT clasS="monofont">__name__</tt> value. If the module does not provide one, or if it is not a string, SystemError is raised and <tT CLAss="monofont">NULL</tt> is returned.</P>
<PRE>
char* PyModule_GetFilename(PyObject *module)
</pre>
<p>Returns the name of the file from which module was loaded using module's <TT CLass="monofont">__file__</tT> attribute. If this is not defined, or if it is not a string, raises SystemError and returns <TT Class="monofont">NULL.</tt><a name="idx1073751224"></a><a name="idx1073751225"></a><a nAme="idx1073751226"></A></p>
<h5>C Objects</h5>
<P>Refer to the document "<a hreF="249.html">Extending and Embedding the Python Interpreter,</a>" ("<i>Providing a C API for an Extension Module</i>"), for more information on using these objects. This document is part of the Python distribution. Note that it is also available on-line at the <TT CLass="monofont">python.org.</tT></P>
<PRe>
PyCObject
</pre>
<P>This subtype of PyObject represents an opaque value, useful for C extension modules that need to pass an opaque value (as a <TT Class="monofont">void*</TT> pointer) through Python code to other C code. It is often used to make a C function pointer defined in one module available to other modules, so the regular import mechanism can be used to access C APIs defined in dynamically loaded modules.</P>
<Pre>
int PyCObject_Check(PyObject *p)
</pre>
<p>Returns <tt class="monofont">true</tt> if its argument is a <tt claSs="monofont">PyCObject.</tT></p>
<prE>
PyObject* PyCObject_FromVoidPtr(void* cobj, void (*destr)(void *))
</pre>
<p>Return value: New reference. Creates a <Tt clASS="monofont">PyCObject</Tt> from the <tt cLASS="monofont">void * cobj.</tt> The <tt CLASs="monofont">destr</tt> function will be called when the object is reclaimed, unless it is <tT CLAss="monofont">NULL.</tt></p>
<pre>
PyObject* PyCObject_FromVoidPtrAndDesc(void* cobj, void* desc,
void (*destr)(void *, void *))
</pre>
<p>Return value: New reference. Creates a <tt class="monofont">PyCObject</tT> from the <tt ClasS="monofont">void *cob</tt>j. The <tt ClasS="monofont">destr</TT> function will be called when the object is reclaimed. The <Tt claSS="monofont">desc</TT> argument can be used to pass extra callback data for the destructor function.</p>
<pre>
void* PyCObject_AsVoidPtr(PyObject* self)
</PRE>
<P>Returns the object <tt clASS="monofont">void *</Tt> that the PyCObject self was created with.</p>
<pre>
void* PyCObject_GetDesc(PyObject* self)
</pre>
<p>Returns the description <tt class="monofont">void *</tt> that the PyCObject self was created with.<a nAme="idx1073751227"></A><a naMe="idx1073751228"></a><a nAme="idx1073751229"></a><A NAMe="idx1073751230"></a><a nAME="idx1073751231"></A><a namE="idx1073751232"></A><A Name="idx1073751233"></a><A NAMe="idx1073751234"></a><a name="idx1073751235"></a><a name="idx1073751236"></a></p>
</font>
<P><TABLE width="100%" border=0><TR valign="top"><TD><font size=1 color="#C0C0C0"><br></font></TD><TD align=right><font size=1 color="#C0C0C0">Last updated on 1/30/2002<br>Python Developer's Handbook, © 2002 Sams Publishing</font></TD></TR></TABLE></P>
<TABLE border=0 width="100%" cellspacing=0 cellpadding=0><TR><td align=left width="15%" class="headingsubbarbg"><a href="263.html" title="Abstract Objects Layer"><font size="1">< BACK</font></a></td><td align=center width="70%" class="headingsubbarbg"><font size="1"><a href="popanote.asp?pubui=oreilly&bookname=0672319942&snode=264" target="_blank" title="Make a public or private annnotation">Make Note</a> | <a href="264.html" title="Use a Safari bookmark to remember this section">Bookmark</a></font></td><td align=right width="15%" class="headingsubbarbg"><a href="265.html" title="Initialization, Finalization, and Threads"><font size="1">CONTINUE ></font></a></td></TR></TABLE>
</TD></TR></TABLE>
<br><TABLE width=100% bgcolor=white border=0 cellspacing=0 cellpadding=5><TR><TD><H4 class=Title>Index terms contained in this section</H4>
<font size=2>
Application Programmers Interface (API)<BR>
Python/C<BR>
<a href="#idx1073751073">Concrete Objects Layer</a> <a href="#idx1073751088">2nd</a> <a href="#idx1073751121">3rd</a> <a href="#idx1073751135">4th</a> <a href="#idx1073751152">5th</a> <a href="#idx1073751166">6th</a> <a href="#idx1073751190">7th</a> <a href="#idx1073751206">8th</a> <a href="#idx1073751228">9th</a><BR>
arrays<BR>
<a href="#idx1073751104">buffer interface support</a><BR>
<a href="#idx1073751101">buffer interface</a><BR>
<a href="#idx1073751117">buffer objects</a><BR>
<a href="#idx1073751110">bufferobject.h header file</a><BR>
<a href="#idx1073751234">C objects</a><BR>
C structures<BR>
<a href="#idx1073751203">complex numbers as</a><BR>
<a href="#idx1073751200">complex number objects</a> <a href="#idx1073751216">2nd</a><BR>
<a href="#idx1073751077">Concrete Objects Layer, Python/C Application Programmers Interface (API)</a> <a href="#idx1073751092">2nd</a> <a href="#idx1073751125">3rd</a> <a href="#idx1073751139">4th</a> <a href="#idx1073751156">5th</a> <a href="#idx1073751170">6th</a> <a href="#idx1073751194">7th</a> <a href="#idx1073751210">8th</a> <a href="#idx1073751232">9th</a><BR>
<a href="#idx1073751162">dictionary objects</a><BR>
<a href="#idx1073751221">file objects</a><BR>
files<BR>
header<BR>
<a href="#idx1073751112">bufferobject.h</a><BR>
<a href="#idx1073751186">floating point objects</a><BR>
functions<BR>
<a href="#idx1073751071">object types</a> <a href="#idx1073751082">2nd</a> <a href="#idx1073751086">3rd</a> <a href="#idx1073751097">4th</a> <a href="#idx1073751116">5th</a> <a href="#idx1073751130">6th</a> <a href="#idx1073751144">7th</a> <a href="#idx1073751161">8th</a> <a href="#idx1073751175">9th</a> <a href="#idx1073751182">10th</a> <a href="#idx1073751199">11th</a> <a href="#idx1073751215">12th</a><BR>
objects<BR>
<a href="#idx1073751119">buffer</a><BR>
<a href="#idx1073751236">C</a><BR>
<a href="#idx1073751202">complex number</a> <a href="#idx1073751218">2nd</a><BR>
<a href="#idx1073751164">dictionary</a><BR>
<a href="#idx1073751223">file</a><BR>
<a href="#idx1073751188">floating point</a><BR>
<a href="#idx1073751147">list</a> <a href="#idx1073751150">2nd</a><BR>
<a href="#idx1073751185">long integer</a><BR>
<a href="#idx1073751160">mapping</a><BR>
<a href="#idx1073751226">module</a><BR>
<a href="#idx1073751085">none</a><BR>
<a href="#idx1073751174">numeric</a> <a href="#idx1073751181">2nd</a> <a href="#idx1073751198">3rd</a> <a href="#idx1073751214">4th</a><BR>
<a href="#idx1073751178">plain integer</a><BR>
<a href="#idx1073751096">sequence</a> <a href="#idx1073751115">2nd</a> <a href="#idx1073751129">3rd</a> <a href="#idx1073751143">4th</a><BR>
<a href="#idx1073751100">string</a><BR>
<a href="#idx1073751133">tuple</a><BR>
<a href="#idx1073751081">type</a><BR>
<a href="#idx1073751109">PyArgs_ParseTuple</a><BR>
header files<BR>
<a href="#idx1073751111">bufferobject.h</a><BR>
interfaces<BR>
<a href="#idx1073751102">buffer</a><BR>
Python/C Application Programmers (API)<BR>
<a href="#idx1073751074">Concrete Objects Layer</a> <a href="#idx1073751089">2nd</a> <a href="#idx1073751122">3rd</a> <a href="#idx1073751136">4th</a> <a href="#idx1073751153">5th</a> <a href="#idx1073751167">6th</a> <a href="#idx1073751191">7th</a> <a href="#idx1073751207">8th</a> <a href="#idx1073751229">9th</a><BR>
layers<BR>
<a href="#idx1073751078">Concrete Objects, Python/C Application Programmers Interface (API)</a> <a href="#idx1073751093">2nd</a> <a href="#idx1073751126">3rd</a> <a href="#idx1073751140">4th</a> <a href="#idx1073751157">5th</a> <a href="#idx1073751171">6th</a> <a href="#idx1073751195">7th</a> <a href="#idx1073751211">8th</a> <a href="#idx1073751233">9th</a><BR>
<a href="#idx1073751145">list objects</a> <a href="#idx1073751148">2nd</a><BR>
<a href="#idx1073751183">long integer objects</a><BR>
<a href="#idx1073751158">mapping objects</a><BR>
methods<BR>
<a href="#idx1073751107">write()</a><BR>
<a href="#idx1073751224">module objects</a><BR>
<a href="#idx1073751083">none objects</a><BR>
<a href="#idx1073751172">numeric objects</a> <a href="#idx1073751179">2nd</a> <a href="#idx1073751196">3rd</a> <a href="#idx1073751212">4th</a><BR>
objects<BR>
<a href="#idx1073751118">buffer</a><BR>
<a href="#idx1073751235">C</a><BR>
<a href="#idx1073751201">complex number</a> <a href="#idx1073751217">2nd</a><BR>
<a href="#idx1073751163">dictionary</a><BR>
<a href="#idx1073751222">file</a><BR>
<a href="#idx1073751187">floating point</a><BR>
<a href="#idx1073751146">list</a> <a href="#idx1073751149">2nd</a><BR>
<a href="#idx1073751184">long integer</a><BR>
<a href="#idx1073751159">mapping</a><BR>
<a href="#idx1073751225">module</a><BR>
<a href="#idx1073751084">none</a><BR>
<a href="#idx1073751173">numeric</a> <a href="#idx1073751180">2nd</a> <a href="#idx1073751197">3rd</a> <a href="#idx1073751213">4th</a><BR>
<a href="#idx1073751075">passing to object types, Python/C Application Programmers Interface (API)</a> <a href="#idx1073751090">2nd</a> <a href="#idx1073751123">3rd</a> <a href="#idx1073751137">4th</a> <a href="#idx1073751154">5th</a> <a href="#idx1073751168">6th</a> <a href="#idx1073751192">7th</a> <a href="#idx1073751208">8th</a> <a href="#idx1073751230">9th</a><BR>
<a href="#idx1073751177">plain integer</a><BR>
Python<BR>
<a href="#idx1073751220">complex numbers as</a><BR>
<a href="#idx1073751095">sequence</a> <a href="#idx1073751114">2nd</a> <a href="#idx1073751128">3rd</a> <a href="#idx1073751142">4th</a><BR>
<a href="#idx1073751099">string</a><BR>
<a href="#idx1073751132">tuple</a><BR>
<a href="#idx1073751080">type</a><BR>
passing<BR>
<a href="#idx1073751076">objects to object types, Python/C Application Programmers Interface (API)</a> <a href="#idx1073751091">2nd</a> <a href="#idx1073751124">3rd</a> <a href="#idx1073751138">4th</a> <a href="#idx1073751155">5th</a> <a href="#idx1073751169">6th</a> <a href="#idx1073751193">7th</a> <a href="#idx1073751209">8th</a> <a href="#idx1073751231">9th</a><BR>
<a href="#idx1073751176">plain integer objects</a><BR>
<a href="#idx1073751108">PyArgs_ParseTuple function</a><BR>
Python objects<BR>
<a href="#idx1073751219">complex numbers as</a><BR>
Python/C Application Programmers Interface (API)<BR>
<a href="#idx1073751072">Concrete Objects Layer</a> <a href="#idx1073751087">2nd</a> <a href="#idx1073751120">3rd</a> <a href="#idx1073751134">4th</a> <a href="#idx1073751151">5th</a> <a href="#idx1073751165">6th</a> <a href="#idx1073751189">7th</a> <a href="#idx1073751205">8th</a> <a href="#idx1073751227">9th</a><BR>
<a href="#idx1073751094">sequence objects</a> <a href="#idx1073751113">2nd</a> <a href="#idx1073751127">3rd</a> <a href="#idx1073751141">4th</a><BR>
<a href="#idx1073751098">string objects</a><BR>
strings<BR>
<a href="#idx1073751103">buffer interface support</a><BR>
structures<BR>
C<BR>
<a href="#idx1073751204">complex numbers as</a><BR>
support<BR>
<a href="#idx1073751105">buffer interface, strings and arrays</a><BR>
<a href="#idx1073751131">tuple objects</a><BR>
<a href="#idx1073751079">type objects</a><BR>
<a href="#idx1073751106">write() method</a><BR>
<BR>
</font></TD></TR></TABLE>
<!--EndOfBrowse-->
</TD></TR></TABLE>
<table width=100% border=0 cellspacing=0 cellpadding=0 bgcolor=#990000><tr><td><p align=center><font size=1 face="verdana,arial,helvetica" color=white>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -