字符编码

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了字符编码相关的知识,希望对你有一定的参考价值。

我实在不想说什么了,这个写的太详细了明确了,跪了的感觉,大王完全不在了

http://www.cnblogs.com/linhaifeng/articles/5950339.html

 

仅仅补充一下

查看python 字符编码
import sys
print(sys.getdefaultencoding())

查看window系统字符编码

技术分享

linux

[[email protected] ~]$ echo $LANG
zh_CN.UTF-8

  

最后加上大王的代码

import sys
print(sys.getdefaultencoding())


msg = "我爱北京天安门"
#msg_gb2312 = msg.decode("utf-8").encode("gb2312")
msg_gb2312 = msg.encode("gb2312") #默认就是unicode,不用再decode,喜大普奔
gb2312_to_unicode = msg_gb2312.decode("gb2312")
gb2312_to_utf8 = msg_gb2312.decode("gb2312").encode("utf-8")

print(msg)
print(msg_gb2312)
print(gb2312_to_unicode)
print(gb2312_to_utf8)

 

以上是关于字符编码的主要内容,如果未能解决你的问题,请参考以下文章