Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import mmap
- import sys
- import struct
- def main(in_file, out_file):
- with open(in_file, "r+b") as f:
- map = mmap.mmap(f.fileno(), 0)
- data = map.readline()
- # Assuming first char is \x00 and
- # data is in blocks of 3.
- pos = 1
- # Output to CSV
- with open(out_file, "w") as o:
- while (pos + 3) < (len(data) - 1):
- row = struct.unpack('BBB', data[pos:pos+3])
- # o.write("{0}, {1}, {2}\n".format(*row))
- o.write(", ".join(row))
- pos += 4
- map.close()
- if __name__ == "__main__":
- if sys.argv[1] == "-h":
- print("Parameters:")
- print("1: Input file")
- print("2: Output file")
- else:
- main(sys.argv[1], sys.argv[2])
Add Comment
Please, Sign In to add comment