Python3将Unicode文字字符串解释为Unicode字符 [英] Python3 interpret unicode literal string as unicode character

查看:170
本文介绍了Python3将Unicode文字字符串解释为Unicode字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在我有一些Unicode文字字符串,例如 \\u0061,默认情况下会解释为6个Unicode字符。如何将其转换为Unicode字符'a'?。

Now I have some unicode literal string like "\\u0061" which is by default interpreted as 6 unicode character. How can I convert it into unicode character 'a' ?.

推荐答案

更简单:

>>> "\\u0061".encode().decode('unicode-escape')
'a'
>>> 

这篇关于Python3将Unicode文字字符串解释为Unicode字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆