Py学习  »  Python

python将unicode代码值转换为字符串,不带“\u”

Allen • 3 年前 • 1121 次点击  

在下面的代码中,

text = "\u54c8\u54c8\u54c8\u54c8"

有没有办法将上面的unicode代码转换为只保留值,并从中删除“\u”。 所以 "\u54c8" 变成 "54c8" 相反

用javascript我可以做到 text.charCodeAt(n).toString(16) ,但我无法用python找到等效的解决方案。

我试着用正则表达式来匹配,

pattern = re.compile('[\u0000-\uFFFF]')

matches = pattern.finditer(text)

for match in matches:
    print(match)

但它所做的只是打印出unicode值所代表的字符。

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/131777
 
1121 次点击  
文章 [ 2 ]  |  最新文章 3 年前