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

📄 multifile-objects.html

📁 一本很好的python的说明书,适合对python感兴趣的人
💻 HTML
字号:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>12.5.1 MultiFile Objects </title>
<META NAME="description" CONTENT="12.5.1 MultiFile Objects ">
<META NAME="keywords" CONTENT="lib">
<META NAME="resource-type" CONTENT="document">
<META NAME="distribution" CONTENT="global">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="STYLESHEET" href="lib.css" tppabs="http://www.python.org/doc/current/lib/lib.css">
<LINK REL="next" href="multifile-example.html" tppabs="http://www.python.org/doc/current/lib/multifile-example.html">
<LINK REL="previous" href="module-multifile.html" tppabs="http://www.python.org/doc/current/lib/module-multifile.html">
<LINK REL="up" href="module-multifile.html" tppabs="http://www.python.org/doc/current/lib/module-multifile.html">
<LINK REL="next" href="multifile-example.html" tppabs="http://www.python.org/doc/current/lib/multifile-example.html">
</head>
<body>
<DIV CLASS="navigation"><table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td><A href="module-multifile.html" tppabs="http://www.python.org/doc/current/lib/module-multifile.html"><img src="previous.gif" tppabs="http://www.python.org/doc/current/icons/previous.gif" border="0" height="32"
  alt="Previous Page" width="32"></A></td>
<td><A href="module-multifile.html" tppabs="http://www.python.org/doc/current/lib/module-multifile.html"><img src="up.gif" tppabs="http://www.python.org/doc/current/icons/up.gif" border="0" height="32"
  alt="Up One Level" width="32"></A></td>
<td><A href="multifile-example.html" tppabs="http://www.python.org/doc/current/lib/multifile-example.html"><img src="next.gif" tppabs="http://www.python.org/doc/current/icons/next.gif" border="0" height="32"
  alt="Next Page" width="32"></A></td>
<td align="center" width="100%">Python Library Reference</td>
<td><A href="contents.html" tppabs="http://www.python.org/doc/current/lib/contents.html"><img src="contents.gif" tppabs="http://www.python.org/doc/current/icons/contents.gif" border="0" height="32"
  alt="Contents" width="32"></A></td>
<td><a href="modindex.html" tppabs="http://www.python.org/doc/current/lib/modindex.html" title="Module Index"><img src="modules.gif" tppabs="http://www.python.org/doc/current/icons/modules.gif" border="0" height="32"
  alt="Module Index" width="32"></a></td>
<td><A href="genindex.html" tppabs="http://www.python.org/doc/current/lib/genindex.html"><img src="index.gif" tppabs="http://www.python.org/doc/current/icons/index.gif" border="0" height="32"
  alt="Index" width="32"></A></td>
</tr></table>
<b class="navlabel">Previous:</b> <a class="sectref" href="module-multifile.html" tppabs="http://www.python.org/doc/current/lib/module-multifile.html">12.5 multifile  </A>
<b class="navlabel">Up:</b> <a class="sectref" href="module-multifile.html" tppabs="http://www.python.org/doc/current/lib/module-multifile.html">12.5 multifile  </A>
<b class="navlabel">Next:</b> <a class="sectref" href="multifile-example.html" tppabs="http://www.python.org/doc/current/lib/multifile-example.html">12.5.2 MultiFile Example</A>
<br><hr></DIV>
<!--End of Navigation Panel-->

<H2>
<BR>
12.5.1 MultiFile Objects 
</H2>

<P>
A <tt class="class">MultiFile</tt> instance has the following methods:

<P>
<dl><dt><b><a name='l2h-2396'><tt class='method'>push</tt></a></b> (<var>str</var>)
<dd>
Push a boundary string.  When an appropriately decorated version of
this boundary is found as an input line, it will be interpreted as a
section-divider or end-marker.  All subsequent
reads will return the empty string to indicate end-of-file, until a
call to <tt class="method">pop()</tt> removes the boundary a or <tt class="method">next()</tt> call
reenables it.

<P>
It is possible to push more than one boundary.  Encountering the
most-recently-pushed boundary will return EOF; encountering any other
boundary will raise an error.
</dl>

<P>
<dl><dt><b><a name='l2h-2397'><tt class='method'>readline</tt></a></b> (<var>str</var>)
<dd>
Read a line.  If the line is data (not a section-divider or end-marker
or real EOF) return it.  If the line matches the most-recently-stacked
boundary, return <code>''</code> and set <code>self.last</code> to 1 or 0 according as
the match is or is not an end-marker.  If the line matches any other
stacked boundary, raise an error.  On encountering end-of-file on the
underlying stream object, the method raises <tt class="exception">Error</tt> unless
all boundaries have been popped.
</dl>

<P>
<dl><dt><b><a name='l2h-2398'><tt class='method'>readlines</tt></a></b> (<var>str</var>)
<dd>
Return all lines remaining in this part as a list of strings.
</dl>

<P>
<dl><dt><b><a name='l2h-2399'><tt class='method'>read</tt></a></b> ()
<dd>
Read all lines, up to the next section.  Return them as a single
(multiline) string.  Note that this doesn't take a size argument!
</dl>

<P>
<dl><dt><b><a name='l2h-2400'><tt class='method'>next</tt></a></b> ()
<dd>
Skip lines to the next section (that is, read lines until a
section-divider or end-marker has been consumed).  Return true if
there is such a section, false if an end-marker is seen.  Re-enable
the most-recently-pushed boundary.
</dl>

<P>
<dl><dt><b><a name='l2h-2401'><tt class='method'>pop</tt></a></b> ()
<dd>
Pop a section boundary.  This boundary will no longer be interpreted
as EOF.
</dl>

<P>
<dl><dt><b><a name='l2h-2402'><tt class='method'>seek</tt></a></b> (<var>pos</var><big>[</big><var>, whence</var><big>]</big>)
<dd>
Seek.  Seek indices are relative to the start of the current section.
The <var>pos</var> and <var>whence</var> arguments are interpreted as for a file
seek.
</dl>

<P>
<dl><dt><b><a name='l2h-2403'><tt class='method'>tell</tt></a></b> ()
<dd>
Return the file position relative to the start of the current section.
</dl>

<P>
<dl><dt><b><a name='l2h-2404'><tt class='method'>is_data</tt></a></b> (<var>str</var>)
<dd>
Return true if <var>str</var> is data and false if it might be a section
boundary.  As written, it tests for a prefix other than <code>'-</code><code>-'</code> at
start of line (which all MIME boundaries have) but it is declared so
it can be overridden in derived classes.

<P>
Note that this test is used intended as a fast guard for the real
boundary tests; if it always returns false it will merely slow
processing, not cause it to fail.
</dl>

<P>
<dl><dt><b><a name='l2h-2405'><tt class='method'>section_divider</tt></a></b> (<var>str</var>)
<dd>
Turn a boundary into a section-divider line.  By default, this
method prepends <code>'-</code><code>-'</code> (which MIME section boundaries have) but
it is declared so it can be overridden in derived classes.  This
method need not append LF or CR-LF, as comparison with the result
ignores trailing whitespace. 
</dl>

<P>
<dl><dt><b><a name='l2h-2406'><tt class='method'>end_marker</tt></a></b> (<var>str</var>)
<dd>
Turn a boundary string into an end-marker line.  By default, this
method prepends <code>'-</code><code>-'</code> and appends <code>'-</code><code>-'</code> (like a
MIME-multipart end-of-message marker) but it is declared so it can be
be overridden in derived classes.  This method need not append LF or
CR-LF, as comparison with the result ignores trailing whitespace.
</dl>

<P>
Finally, <tt class="class">MultiFile</tt> instances have two public instance variables:

<P>
<dl><dt><b><a name='l2h-2407'><tt class='member'>level</tt></a></b>
<dd>
Nesting depth of the current part.
</dl>

<P>
<dl><dt><b><a name='l2h-2408'><tt class='member'>last</tt></a></b>
<dd>
True if the last end-of-file was for an end-of-message marker. 
</dl>

<P>

<DIV CLASS="navigation"><p><hr><table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td><A href="module-multifile.html" tppabs="http://www.python.org/doc/current/lib/module-multifile.html"><img src="previous.gif" tppabs="http://www.python.org/doc/current/icons/previous.gif" border="0" height="32"
  alt="Previous Page" width="32"></A></td>
<td><A href="module-multifile.html" tppabs="http://www.python.org/doc/current/lib/module-multifile.html"><img src="up.gif" tppabs="http://www.python.org/doc/current/icons/up.gif" border="0" height="32"
  alt="Up One Level" width="32"></A></td>
<td><A href="multifile-example.html" tppabs="http://www.python.org/doc/current/lib/multifile-example.html"><img src="next.gif" tppabs="http://www.python.org/doc/current/icons/next.gif" border="0" height="32"
  alt="Next Page" width="32"></A></td>
<td align="center" width="100%">Python Library Reference</td>
<td><A href="contents.html" tppabs="http://www.python.org/doc/current/lib/contents.html"><img src="contents.gif" tppabs="http://www.python.org/doc/current/icons/contents.gif" border="0" height="32"
  alt="Contents" width="32"></A></td>
<td><a href="modindex.html" tppabs="http://www.python.org/doc/current/lib/modindex.html" title="Module Index"><img src="modules.gif" tppabs="http://www.python.org/doc/current/icons/modules.gif" border="0" height="32"
  alt="Module Index" width="32"></a></td>
<td><A href="genindex.html" tppabs="http://www.python.org/doc/current/lib/genindex.html"><img src="index.gif" tppabs="http://www.python.org/doc/current/icons/index.gif" border="0" height="32"
  alt="Index" width="32"></A></td>
</tr></table>
<b class="navlabel">Previous:</b> <a class="sectref" href="module-multifile.html" tppabs="http://www.python.org/doc/current/lib/module-multifile.html">12.5 multifile  </A>
<b class="navlabel">Up:</b> <a class="sectref" href="module-multifile.html" tppabs="http://www.python.org/doc/current/lib/module-multifile.html">12.5 multifile  </A>
<b class="navlabel">Next:</b> <a class="sectref" href="multifile-example.html" tppabs="http://www.python.org/doc/current/lib/multifile-example.html">12.5.2 MultiFile Example</A>
</DIV>
<!--End of Navigation Panel-->
<ADDRESS>
<hr>See <i><a href="about.html" tppabs="http://www.python.org/doc/current/lib/about.html">About this document...</a></i> for information on suggesting changes.
</ADDRESS>
</BODY>
</HTML>

⌨️ 快捷键说明

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