且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在python中将unicode字符串转换为普通文本

更新时间:2023-11-07 15:44:34

您可以使用 unicode-escape 编解码器可消除双反斜杠并有效地使用字符串.

You can use the unicode-escape codec to get rid of the doubled-backslashes and use the string effectively.

假设titlestr,则需要先对字符串进行编码,然后再解码回unicode(str).

Assuming that title is a str, you will need to encode the string first before decoding back to unicode(str).

>>> t = title.encode('utf-8').decode('unicode-escape')
>>> t
'ისრაელი == იერუსალიმი'

如果titlebytes实例,则可以直接解码:

If title is a bytes instance you can decode directly:

>>> t = title.decode('unicode-escape')
>>> t
'ისრაელი == იერუსალიმი'