小编New*_*der的帖子

Struct.error: unpack 需要 16 字节的缓冲区

我有这种格式的二进制文件,(b'A\xd9\xa5\x1ab\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x0b\xda\xa5\x1ab\x00\x00\x00\x02\x00\x00\x00\x02\x00\x00\x00\xcd\xdb\xa5\x1ab\x00\x00\x00\x04\x00\x00\x00\x01\x00\x00\x00\xff\xdb\xa5\x1ab\x00\x00\x00\x05\x00\x00\x00\x01\x00\x00\x00\xe9\xdc\xa5\x1ab\x00\x00\x00\x06\x00\x00\x00\x02\x00\x00\x00\xf7\xdc\xa5\x1ab\x00\x00\x00\x08\x00\x00\x00\x02\x00\x00\x00\x1b\xdd\xa5\x1a')我将该文件作为用户输入并读取read_file变量(类字节对象)中的文件。我需要使用整数模式(int、int、int、int)将其转换为 ascii ) 每个int4 个字节。我正在尝试使用struct库来解压缩它。我写了以下命令,但它给了我以下错误:

错误

print(unpack("IIII", read_file))
struct.error: unpack requires a buffer of 16 bytes
Run Code Online (Sandbox Code Playgroud)

代码

    for (dirpath, dirnames, filenames) in walk('/Users/amathur1/PycharmProjects/learningpython/NAWF_VRG_G'):
        count = 1
        for file in filenames:
            print(count, " : ", file)
            count = count + 1
        print("select file you want to convert")
        input_file = input()
        print("Selected file number is : ", input_file)

        #To open the selected file
    with open(dirpath + "/" + filenames[int(input_file) - 1], 'rb') as file: …
Run Code Online (Sandbox Code Playgroud)

python-3.x

5
推荐指数
1
解决办法
4万
查看次数

标签 统计

python-3.x ×1