Guest User

Untitled

a guest
Jun 17th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. import mmap
  2. import sys
  3. import struct
  4.  
  5. def main(in_file, out_file):
  6. with open(in_file, "r+b") as f:
  7. map = mmap.mmap(f.fileno(), 0)
  8. data = map.readline()
  9. # Assuming first char is \x00 and
  10. # data is in blocks of 3.
  11. pos = 1
  12. # Output to CSV
  13. with open(out_file, "w") as o:
  14. while (pos + 3) < (len(data) - 1):
  15. row = struct.unpack('BBB', data[pos:pos+3])
  16. # o.write("{0}, {1}, {2}\n".format(*row))
  17. o.write(", ".join(row))
  18. pos += 4
  19. map.close()
  20.  
  21.  
  22. if __name__ == "__main__":
  23. if sys.argv[1] == "-h":
  24. print("Parameters:")
  25. print("1: Input file")
  26. print("2: Output file")
  27. else:
  28. main(sys.argv[1], sys.argv[2])
Add Comment
Please, Sign In to add comment