-1

How to open a dump file (binary)? the answer provided in this question isn't working

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)
  • file1: 367kb
  • file2: 1kb
  • file3: 1000kbp

The output file is only 5kb

When I count lines in the file it returns 4 when I know its much bigger. I think it has to do with the HEX representation which python isn't able to parse?

Tony Tannous
  • 14,154
  • 10
  • 50
  • 86
  • 1
    How many lines in each file that you have? Have you tried to write into `wb` mode? Also, you probably need to read files into `rb` mode. – Dmytro Chasovskyi Jan 15 '19 at 10:23

1 Answers1

1

Hi you are opening the output file with 'w' which won't work mostly for binary files you can open file in wb and then try it.

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)
Amit Nanaware
  • 3,203
  • 1
  • 6
  • 19