Python cannot encode the word "constant" with big5. The, decode () function encounters an error with F9DA (the big5 code of "constant").

execute:

"".encode("big5")

error report:

UnicodeEncodeError: "big5" codec can"t encode character "\u6052" in position 0: illegal multibyte sequence

execute:

b"\xf9\xda".decode("big5")

error report:

UnicodeDecodeError: "big5" codec can"t decode byte 0xf9 in position 0: illegal multibyte sequence

big5 code table

Jan.18,2022

the simplest way must be to change it to traditional Chinese characters. The method of
trouble is to replace the characters that cannot be encoded with Unicode code first, then decode them and then process them by yourself. The code is as follows:

>>> foo = ''.encode(encoding='big5', errors='backslashreplace')
>>> foo
b'\\u6052\xab\xed'
>>> temp = foo.decode(encoding='big5', errors='backslashreplace')
>>> temp
'\\u6052'
>>> bar = repr(temp).replace('\\\\', '\\')
>>> bar
"'\\u6052'"
>>> eval(bar)
''

big5hkscs Hong Kong Supplementary character set

>>> ''.encode('big5hkscs')
b'\xf9\xda'
>>> b'\xf9\xda'.decode('big5hkscs')
''
>>> 
Menu