Created
October 10, 2010 08:20
-
-
Save kennethreitz/619082 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment