如何打开转储文件(二进制)? this问题中提供的答案无效
filenames = ['file1.dmp', "file2.dmp", "file3.dmp"]
with open('test_file.obj', 'w') as outfile:
for fname in filenames:
with open(fname) as infile:
for line in infile:
outfile.write(line)
输出文件只有5kb
当我计算文件中的行数时,当我知道它的行数更大时,它将返回4。我认为这与python无法解析的HEX表示有关吗?
答案 0 :(得分:1)
您好,您正在使用“ w”打开输出文件,该文件在大多数情况下不适用于二进制文件,您可以在wb中打开文件然后尝试。
filenames = ['file1.dmp', "file2.dmp", "file3.dmp"]
with open('test_file.obj', 'wb') as outfile:
for fname in filenames:
with open(fname, 'rb') as infile:
for line in infile:
outfile.write(line)