“surrogateescape” cannot escape certain characters

后端 未结 3 1152
你的背包
你的背包 2021-01-17 18:30

Regarding reading and writing text files in Python, one of the main Python contributors mentions this regarding the surrogateescape Unicode Error Handler:

3条回答
  •  南方客
    南方客 (楼主)
    2021-01-17 18:44

    Why might the surrogateescape Unicode Error Handler be returning a character that is not ASCII?

    Because that's what it explicitly does. That way you can use the same error handler the other way and it will know what to do.

    3>> b"'Zo\xc3\xab\\'s'".decode('ascii', errors='surrogateescape')
    "'Zo\udcc3\udcab\\'s'"
    3>> "'Zo\udcc3\udcab\\'s'".encode('ascii', errors='surrogateescape')
    b"'Zo\xc3\xab\\'s'"
    

提交回复
热议问题