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

📄 codec-objects.html

📁 一本很好的python的说明书,适合对python感兴趣的人
💻 HTML
字号:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>4.7.1.1 Codec Objects </title>
<META NAME="description" CONTENT="4.7.1.1 Codec 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="stream-writer-objects.html" tppabs="http://www.python.org/doc/current/lib/stream-writer-objects.html">
<LINK REL="previous" HREF="node80.html" tppabs="http://www.python.org/doc/current/lib/node80.html">
<LINK REL="up" HREF="node80.html" tppabs="http://www.python.org/doc/current/lib/node80.html">
<LINK REL="next" href="stream-writer-objects.html" tppabs="http://www.python.org/doc/current/lib/stream-writer-objects.html">
</head>
<body>
<DIV CLASS="navigation"><table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td><A HREF="node80.html" tppabs="http://www.python.org/doc/current/lib/node80.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="node80.html" tppabs="http://www.python.org/doc/current/lib/node80.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="stream-writer-objects.html" tppabs="http://www.python.org/doc/current/lib/stream-writer-objects.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="node80.html" tppabs="http://www.python.org/doc/current/lib/node80.html">4.7.1 Codec Base Classes</A>
<b class="navlabel">Up:</b> <a class="sectref" HREF="node80.html" tppabs="http://www.python.org/doc/current/lib/node80.html">4.7.1 Codec Base Classes</A>
<b class="navlabel">Next:</b> <a class="sectref" href="stream-writer-objects.html" tppabs="http://www.python.org/doc/current/lib/stream-writer-objects.html">4.7.1.2 StreamWriter Objects</A>
<br><hr></DIV>
<!--End of Navigation Panel-->

<H3>
<BR>
4.7.1.1 Codec Objects 
</H3>

<P>
The <tt class="class">Codec</tt> class defines these methods which also define the
function interfaces of the stateless encoder and decoder:

<P>
<dl><dt><b><a name='l2h-661'><tt class='method'>encode</tt></a></b> (<var>input</var><big>[</big><var>, errors</var><big>]</big>)
<dd>
  Encodes the object <var>input</var> and returns a tuple (output object,
  length consumed).

<P>
<var>errors</var> defines the error handling to apply. It defaults to
  <code>'strict'</code> handling.

<P>
The method may not store state in the <tt class="class">Codec</tt> instance. Use
  <tt class="class">StreamCodec</tt> for codecs which have to keep state in order to
  make encoding/decoding efficient.

<P>
The encoder must be able to handle zero length input and return an
  empty object of the output object type in this situation.
</dl>

<P>
<dl><dt><b><a name='l2h-662'><tt class='method'>decode</tt></a></b> (<var>input</var><big>[</big><var>, errors</var><big>]</big>)
<dd>
  Decodes the object <var>input</var> and returns a tuple (output object,
  length consumed).

<P>
<var>input</var> must be an object which provides the <code>bf_getreadbuf</code>
  buffer slot.  Python strings, buffer objects and memory mapped files
  are examples of objects providing this slot.

<P>
<var>errors</var> defines the error handling to apply. It defaults to
  <code>'strict'</code> handling.

<P>
The method may not store state in the <tt class="class">Codec</tt> instance. Use
  <tt class="class">StreamCodec</tt> for codecs which have to keep state in order to
  make encoding/decoding efficient.

<P>
The decoder must be able to handle zero length input and return an
  empty object of the output object type in this situation.
</dl>

<P>
The <tt class="class">StreamWriter</tt> and <tt class="class">StreamReader</tt> classes provide
generic working interfaces which can be used to implement new
encodings submodules very easily. See <tt class="module">encodings.utf_8</tt> for an
example on how this is done.

<P>

<DIV CLASS="navigation"><p><hr><table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td><A HREF="node80.html" tppabs="http://www.python.org/doc/current/lib/node80.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="node80.html" tppabs="http://www.python.org/doc/current/lib/node80.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="stream-writer-objects.html" tppabs="http://www.python.org/doc/current/lib/stream-writer-objects.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="node80.html" tppabs="http://www.python.org/doc/current/lib/node80.html">4.7.1 Codec Base Classes</A>
<b class="navlabel">Up:</b> <a class="sectref" HREF="node80.html" tppabs="http://www.python.org/doc/current/lib/node80.html">4.7.1 Codec Base Classes</A>
<b class="navlabel">Next:</b> <a class="sectref" href="stream-writer-objects.html" tppabs="http://www.python.org/doc/current/lib/stream-writer-objects.html">4.7.1.2 StreamWriter Objects</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 + -