使用Python解除字符串中的字符 [英] Unescaping Characters in a String with Python

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

问题描述

我提出了一个JSON请求,它提供了一个使用 Unicode字符代码的字符串像:

I made a JSON request that gives me a string that uses Unicode character codes that looks like:

s = "\u003Cp\u003E"

我想将其转换为:

s = "<p>"

在Python中最好的方法是什么?

What's the best way to do this in Python?

请注意,这与这一个相同的问题,只有在Ruby以外的Python中。我也使用 Posterous API

Note, this is the same question as this one, only in Python except Ruby. I am also using the Posterous API.

推荐答案

如果数据来自JSON,则 json 模块应该已经为您解码了这些转义:

If the data came from JSON, the json module should already have decoded these escapes for you:

>>> import json
>>> json.loads('"\u003Cp\u003E"')
u'<p>'

这篇关于使用Python解除字符串中的字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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