【发布时间】:2012-09-08 11:12:04
【问题描述】:
在python中:
>>> "\xc4\xe3".decode("gbk").encode("utf-8")
'\xe4\xbd\xa0'
>>> "\xc4\xe3".decode("gbk")
u'\u4f60'
我们可以得出两个结论:
1.\xc4\xe3 in gbk 编码 = \xe4\xbd\xa0 in utf-8
2.\xc4\xe3 in gbk encode = \x4f\x60 in unicode(或者说在ucs-2中)
在R中:
> iconv("\xc4\xe3",from="gbk",to="utf-8",toRaw=TRUE)
[[1]]
[1] e4 bd a0
> iconv("\xc4\xe3",from="gbk",to="unicode",toRaw=TRUE)
[[1]]
[1] ff fe 60 4f
现在,结论1是正确的,它在python中和在R中是一样的
结论2是一个谜,
gbk 编码 = 中的 \xc4\xe3 到底是什么?在 unicode 中。
在 python 中是 u'\u4f60',在 R 中是 ff fe 60 4f
平等吗?哪一个是正确的?它们都正确吗?
【问题讨论】:
-
Unicode in Wikipedia: "Unicode可以通过不同的字符编码来实现。最常用的编码是UTF-8、UTF-16和现在已经过时的UCS-2.... "
-
这篇维基百科文章讨论了 GBK 编码。 en.wikipedia.org/wiki/GBK本文介绍python中的Unicodedocs.python.org/howto/unicode.html
-
请阅读@delnan 评论下的文章 - 真的。