在Python中将字节字符串解码为西里尔语

问题描述 投票:0回答:1

我有一个像这样的字节字符串,它应该是西里尔字符中的

Сравнение

a = b'Сравнение'

将其解码为 UTF-8 没有帮助:

a = b'Сравнение'
a.decode("utf-8") # prints same Ср... string

这是什么编码以及如何解码该字符串?

我正在使用 Google Colab 和 Python 3.10.12。

这个在线解码器应用自动解码后表示必须从UTF-8解码为UTF-8。

python python-3.x utf-8 decode
1个回答
2
投票

您可以使用

html.unescape

import html

a = b"Сравнение"
decoded_string = html.unescape(a.decode("utf-8"))

print(decoded_string)

打印:

Сравнение
© www.soinside.com 2019 - 2024. All rights reserved.