i want to convert the chinese character to the unicode format, like '\uXXXX' but when i use str.encode('utf-16be'), it'll show that:
b'\xOO\xOO' so, i write some code to perform my request as below:
data="index=索引?" print(data.encode('UTF-16LE')) def convert(s): returnCode=[] temp='' for n in s.encode('utf-16be'): if temp=='': if str.replace(hex(n),'0x','')=='0': temp='00' continue temp+=str.replace(hex(n),'0x','') else: returnCode.append(temp+str.replace(hex(n),'0x','')) temp='' return returnCode print(convert(data)) can someone give me suggestions to do this conversion in python 3.x?
"index=索引?".encode('utf-16be')givesb'\x00i\x00n\x00d\x00e\x00x\x00=}"_\x15\x00?'. What output did you want instead?index=\u0069\u006e\u0064\u0065\u0078\u003d\u7d22\u5f15\u003f