Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/361.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 串联转储文件_Python - Fatal编程技术网

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模式。