Python汉字字符编码转换

python下由于汉字分属不同unicode的区段,造成转换混乱,尤其是知网之类的pdf文件转换过程中。有时需要根据汉字来判断编码,然后再进行处理。

import json
s = ‘易易’
print(json.dumps(s))

这样可以得到不同的编码:”\u6613\uf9e0″。后一个属于中日韩统一表意文字。

同样

s =’\\u’+’f9e0′
ss = s.encode(‘utf-8’).decode(‘unicode_escape’)

这样可以得到编码对应的汉字。

Leave a Reply

您的电子邮箱地址不会被公开。 必填项已用 * 标注

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>