Why doesn't this conversion to utf8 work?

后端 未结 4 884
醉梦人生
醉梦人生 2020-12-08 22:35

I have a subprocess command that outputs some characters such as \'\\xf1\'. I\'m trying to decode it as utf8 but I get an error.

s = \'\\xf1\'
s.decode(\'utf         


        
4条回答
  •  忘掉有多难
    2020-12-08 23:03

    My understanding is that latin1 is a subset of utf8.

    Wrong. Latin-1, aka ISO 8859-1 (and sometimes erroneously as Windows-1252), is not a subet of UTF-8. ASCII, on the other hand, is a subset of UTF-8. ASCII strings are valid UTF-8 strings, but generalized Windows-1252 or ISO 8859-1 strings are not valid UTF-8, which is why s.decode('UTF-8') is throwing a UnicodeDecodeError.

提交回复
热议问题