gpt4 book ai didi

python-3.x - 结构错误 : unpack requires a buffer of 16 bytes

转载 作者:行者123 更新时间:2023-12-03 16:24:40 25 4
gpt4 key购买 nike

我有这种格式的二进制文件 (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 每个 int 4 个字节。我正在尝试使用 struct 来执行此操作库来解压它。我写了以下命令,但它给了我以下错误:

错误

print(unpack("IIII", read_file))
struct.error: unpack requires a buffer of 16 bytes

代码
    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:
# Reading the selected file i.e. file
read_file = file.read()
print(unpack("IIII", read_file))

最佳答案

您的文件似乎大于 4 个整数(16 字节)的大小;如果,如您所说,每组 4 个整数都需要转换,那么您必须将文件中的数据分解成一系列该大小的块。

关于python-3.x - 结构错误 : unpack requires a buffer of 16 bytes,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51110525/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com