Iterate Big5 charset in python

101 Views Asked by At

I want to get the char in 0xA440-0xC67E with big5 encoding.

I can get the char by decoding byte code like b'\xa4\x41'.decode('big5'), and how can I put this in for loop?

I can't modify it in format way like b'\x%x\x%x' % (0xa4, 0x41).
It will return error "(value error) invalid \x escape at position 0"

1

There are 1 best solutions below

1
DoubleOZ On

Add backslash to your string. Instead of: b'\x%x\x%x' % (0xa4, 0x41) Try like so: b'\\x%x\\x%x' % (0xa4, 0x41)

This should prevent your error, and the output string will remain with one backslash.