我有一个二进制文件,其中包含一行:abcd1234
在 Python 中,使用
filecontent = f_obj.read()
结果在:
filecontent = b'abcd1234'
我想将filecontent
的结果存储到字节数组中,如下所示:
array[0] = 0xab
array[1] = 0xcd
array[2] = 0x12
array[3] = 0x34
有没有一个 Python 函数可以进行这种转换?
filecontent = filecontent.decode("utf-8") # to remove the b' ' from the string
filecontent = bytearray.fromhex(filecontent)