Why doesn't this conversion to utf8 work?

后端 未结 4 868
醉梦人生
醉梦人生 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:25

    It's the first byte of a multi-byte sequence in UTF-8, so it's not valid by itself.

    In fact, it's the first byte of a 4 byte sequence.

    Bits Last code point Byte 1   Byte 2   Byte 3   Byte 4   Byte 5   Byte 6
    21   U+1FFFFF        11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
    

    See here for more info.

提交回复
热议问题