在python中进行编码转换都是通过unicode作为中间值实现的。

decode的作用是将其他编码的字符串转换成unicode编码,如str1.decode(gb2312),表示将gb2312编码的字符串转换成unicode编码。

encode的作用是将unicode编码转换成其他编码的字符串,如str2.encode(gb2312),表示将unicode编码的字符串转换成gb2312编码。

<div class="line number5 index4 alt2" style="font-size:13.3333339691162px;font-family:Monaco,Menlo,Consolas,'Courier New',monospace;line-height:14.6666669845581px;color:rgb(51,51,51);border:0px !important;overflow:visible !important;vertical-align:baseline !important;min-height:auto !important;background-color:rgb(245,245,245);">
<code class="python plain" style="font-family:Monaco,monospace;border:0px !important;line-height:1.1em !important;overflow:visible !important;vertical-align:baseline !important;min-height:auto !important;font-size:13px !important;color:rgb(0,0) !important;background:none !important;">>>><code class="python keyword" style="font-family:Monaco,monospace;border:0px !important;line-height:1.1em !important;overflow:visible !important;vertical-align:baseline !important;font-weight:700 !important;min-height:auto !important;font-size:13px !important;color:rgb(255,120,0) !important;background:none !important;">import<code class="python plain" style="font-family:Monaco,0) !important;background:none !important;">codecs

dawei

【声明】:唐山站长网内容转载自互联网,其相关言论仅代表作者个人观点绝非权威,不代表本站立场。如您发现内容存在版权问题,请提交相关链接至邮箱:bqsm@foxmail.com,我们将及时予以处理。