<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[运维进行时]]></title> 
<link>https://blog.liuts.com/index.php</link> 
<description><![CDATA[互联网运维与架构]]></description> 
<language>zh-cn</language> 
<copyright><![CDATA[运维进行时]]></copyright>
<item>
<link>https://blog.liuts.com/post//</link>
<title><![CDATA[python 编码转换]]></title> 
<author>root &lt;admin@yourname.com&gt;</author>
<category><![CDATA[Python]]></category>
<pubDate>Sat, 22 Sep 2007 06:48:55 +0000</pubDate> 
<guid>https://blog.liuts.com/post//</guid> 
<description>
<![CDATA[ 
	python常用编码转换函数：<br/>(1)&nbsp;&nbsp; unicode()&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 全局函数,将str字符串从其它编码(如gb2312)转换为unicode对象<br/>(2)&nbsp;&nbsp; str.decode()&nbsp;&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; str字符串的方法,将str字符串从其它编码(如gb2312)转换为unicode对象,与unicode()很相似.<br/>(3)&nbsp;&nbsp; str.encode()&nbsp;&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; str字符串的方法,<br/>(4)&nbsp;&nbsp;unicode.encode() <br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; unicode对象的方法,将unicode对象转成其它相应编码的str字符串对象,如gb2312.<br/>(5)&nbsp;&nbsp;unicode.decode() <br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; unicode对象的方法<br/>应用例子:<br/><textarea name="code" class="python" rows="15" cols="100">
>>> s="中文"&nbsp;&nbsp;#str对象
>>> ss=u"中文"&nbsp;&nbsp;#unicode对象
>>> type(s)
<type 'str'>
>>> type(ss)
<type 'unicode'>
>>> s1=unicode(s,'mbcs')&nbsp;&nbsp;# str对象&nbsp;&nbsp;-->&nbsp;&nbsp;unicode对象
>>> s1
u'&#92;u4e2d&#92;u6587'&nbsp;&nbsp;&nbsp;&nbsp; 
>>> type(s1)
<type 'unicode'>
>>> s3=ss.encode('mbcs')&nbsp;&nbsp;# unicode对象 -->&nbsp;&nbsp;str对象 
>>> s3
'&#92;xd6&#92;xd0&#92;xce&#92;xc4'
>>> type(s3)
<type 'str'></P>
</textarea><br/>Tags - <a href="https://blog.liuts.com/tags/%25E7%25BC%2596%25E7%25A0%2581%25E8%25BD%25AC%25E6%258D%25A2/" rel="tag">编码转换</a>
]]>
</description>
</item><item>
<link>https://blog.liuts.com/post//#blogcomment</link>
<title><![CDATA[[评论] python 编码转换]]></title> 
<author> &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Thu, 01 Jan 1970 00:00:00 +0000</pubDate> 
<guid>https://blog.liuts.com/post//#blogcomment</guid> 
<description>
<![CDATA[ 
	
]]>
</description>
</item>
</channel>
</rss>