简体   繁体   English

解码法语口音不适用于 utf-8

[英]Decode french accent not working with utf-8

I try to decode this very simple variable b'autorite nt\\syst\x8ame\r\n'我尝试解码这个非常简单的变量b'autorite nt\\syst\x8ame\r\n'

b'autorite nt\\syst\x8ame\r\n'
>>> t.decode('utf-8')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x8a in position 16: invalid start byte

But nothing is working, it should print autorite nt\\système but I cannot find a way to print it correctly但是没有任何效果,它应该打印autorite nt\\système但我找不到正确打印它的方法

It isn't encoded as UTF-8.它没有编码为 UTF-8。 It might be cp437, or any of these: cp437, cp720, cp850, cp857, cp858, cp860, cp861, cp863, cp865 ( source )它可能是 cp437,或以下任何一种:cp437、cp720、cp850、cp857、cp858、cp860、cp861、cp863、cp865(来源

>>> print(b'autorite nt\\syst\x8ame\r\n'.decode('cp437'))
autorite nt\système

You can use decode with utf-8 encoding and replacement rule.您可以将解码与utf-8编码和替换规则一起使用。

t = b'autorite nt\\syst\x8ame\r\n'
t.decode('utf-8', 'replace')

Further reading: https://docs.python.org/3/howto/unicode.html进一步阅读: https://docs.python.org/3/howto/unicode.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM