Python 串联转储文件
如何打开转储文件二进制文件?所提供的答案不起作用Python 串联转储文件,python,Python,如何打开转储文件二进制文件?所提供的答案不起作用 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(lin
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)
文件1:367kb
文件2:1kb
文件3:1000kbp
输出文件只有5kb
当我计算文件中的行数时,当我知道它要大得多时,它返回4。我认为这与python无法解析的十六进制表示法有关?您好,您正在使用“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)
每个文件中有多少行?您是否尝试过写入wb模式?此外,您可能需要将文件读入rb模式。