我下载了一个 Facebook 消息数据集,它的格式如下:

f\u00c3\u00b8rste student

它应该是 første student 但我似乎无法正确解码它。

我试过了:
str = 'f\u00c3\u00b8rste student'
print(str)
# 'første student'

str = 'f\u00c3\u00b8rste student'
print(str.encode('utf-8'))
# b'f\xc3\x83\xc2\xb8rste student'

但它没有用。

最佳答案

要撤消已发生的任何编码错误,您首先需要通过在 ISO-8859-1 (Latin-1) 中编码,然后在解码为 UTF-8 之后将字符转换为具有相同序数的字节:

>>> 'f\u00c3\u00b8rste student'.encode('iso-8859-1').decode('utf-8')
'første student'

关于python - 如何在 python 中解码这个字符串?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/53602446/

10-11 22:48
查看更多