python編碼問題

參考 

http://blog.csdn.net/gukesdo/article/details/7336936

http://www.jb51.net/article/17560.htm

各種碼   ascii碼     unicode碼    utf8碼   gb2312碼   gbk碼

字符串在Python內部的表示是unicode編碼,因此,在做編碼轉換時,通常需要以unicode作爲中間編碼,即先將其他編碼的字符串解碼(decode)成unicode,再從unicode編碼(encode)成另一種編碼。 

decode的作用是將其他編碼的字符串轉換成unicode編碼,如str1.decode('gb2312'),表示將gb2312編碼的字符串str1轉換成unicode編碼。 

encode的作用是將unicode編碼轉換成其他編碼的字符串,如str2.encode('gb2312'),表示將unicode編碼的字符串str2轉換成gb2312編碼。 

數據庫中的編碼問題 如下

print s._getItemByTaxRegCode("320100100389067")[2].encode('latin-1').decode('gbk')


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章