小编mar*_*tin的帖子

在Python中将u"string"转换为"string"而不改变编码

我有以下内容:

u'\x96'
Run Code Online (Sandbox Code Playgroud)

我想将其转换为以下内容:

'\x96'
Run Code Online (Sandbox Code Playgroud)

有没有办法做到这一点?str()不起作用,使用.encode(...)时更改编码.我的主要目标是能够获得以下结果,因此任何到达那里的快捷方式也将被接受:

>>> '\x96'.decode("cp1252")
u'\u2013'
Run Code Online (Sandbox Code Playgroud)

换句话说,我有u'\x96',我想要u'\u2013'.任何帮助,将不胜感激.

我正在使用Python 2.7.

python unicode

5
推荐指数
1
解决办法
2314
查看次数

标签 统计

python ×1

unicode ×1