Binary files

From XPUB & Lens-Based wiki
Revision as of 17:08, 8 April 2009 by Michael Murtaugh (talk | contribs) (New page: Simple example of parsing a binary file. <source lang="python"> #!/usr/bin/python import os, sys fpath = sys.argv[1] size = os.stat(fpath)[6] print size, (size / 1024.0) file = open(fp...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Simple example of parsing a binary file.

#!/usr/bin/python

import os, sys
fpath = sys.argv[1]

size = os.stat(fpath)[6]
print size, (size / 1024.0)

file = open(fpath, "rb")
count = 0
while 1:
	chunk = file.read(1024)
	if not chunk:
		break
	count += 1
	print ".",
print

file.close()
print count, "megabytes"