python中\\uXXXX等字符串的转换 [英] Conversion of strings like \\uXXXX in python

查看:36
本文介绍了python中\\uXXXX等字符串的转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个像 \uXXXX(表示)这样的字符串,我需要将它转换为 unicode.我从 3rd 方服务收到它,所以 python 解释器不会转换它,我需要在我的代码中进行转换.我如何在 Python 中做到这一点?

<预><代码>>>>秒u'\\u0e4f\\u032f\\u0361\\u0e4f'

解决方案

>>>u'\\u0e4f\\u032f\\u0361\\u0e4f'.decode('unicode-escape')你'\u0e4f\u032f\u0361\u0e4f'>>>打印 u'\\u0e4f\\u032f\\u0361\\u0e4f'.decode('unicode-escape')๏̯͡๏

I have a string like \uXXXX (representation) and I need to convert it into unicode. I receive it from 3rd party service so python interpreter doesn't convert it and I need conversion in my code. How do I do it in Python?

>>> s
u'\\u0e4f\\u032f\\u0361\\u0e4f'

解决方案

>>> u'\\u0e4f\\u032f\\u0361\\u0e4f'.decode('unicode-escape')
u'\u0e4f\u032f\u0361\u0e4f'
>>> print u'\\u0e4f\\u032f\\u0361\\u0e4f'.decode('unicode-escape')
๏̯͡๏

这篇关于python中\\uXXXX等字符串的转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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