python bytes to C array (like xxd program"

后端 未结 3 1990
自闭症患者
自闭症患者 2021-01-24 07:00

In python3 I have some bytes. I want to export them to C source code. Outside python I use \"xxd -i binary_file\" command.

Example:

x = b\'abc123\'
print         


        
3条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-24 07:29

    1. print([hex(i) for in x]) 
    
    2. print(a.hex())
    

    Results will be:

    1. ['0x61', '0x62', '0x63', '0x31', '0x32', '0x33']
    2. '616263313233'
    

提交回复
热议问题