Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/298.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
python中\\uxxx等字符串的转换_Python_Unicode - Fatal编程技术网

python中\\uxxx等字符串的转换

python中\\uxxx等字符串的转换,python,unicode,Python,Unicode,我有一个类似\uxxx(表示法)的字符串,需要将其转换为unicode。 我从第三方服务接收它,所以python解释器不会转换它,我需要在代码中进行转换。 如何在Python中实现它 >>> s u'\\u0e4f\\u032f\\u0361\\u0e4f' .encode()和.decode()方法支持一个有趣的方法。第二个表中的魔法包括unicode\u escapePython3: bytes("\\u0e4f\\u032f\\u0361\\u0e4f&quo

我有一个类似\uxxx(表示法)的字符串,需要将其转换为unicode。 我从第三方服务接收它,所以python解释器不会转换它,我需要在代码中进行转换。 如何在Python中实现它

>>> s
u'\\u0e4f\\u032f\\u0361\\u0e4f'
.encode()
.decode()
方法支持一个有趣的方法。第二个表中的魔法包括
unicode\u escape

Python3:

bytes("\\u0e4f\\u032f\\u0361\\u0e4f", "ascii").decode("unicode-escape")

AttributeError:'str'对象没有属性“decode”
@Kid\u Learning\u C那么你可能在Python 3上了;这是一个适用于Python2的老答案。见例。
bytes("\\u0e4f\\u032f\\u0361\\u0e4f", "ascii").decode("unicode-escape")