[python-win32] print file byte contents distribution

Vernon Cole vernondcole at gmail.com
Fri Mar 4 21:20:03 CET 2011


What a nifty script!  I love it!
Here's my version.  I tested using a 800 KByte image file and it runs
in a blink. Dictionary access in Python is very fast.
<code>
counter = {}

for bytes in open('c:\\temp\\16.jpg', "rb").read():
   try:
       counter[bytes] += 1
   except KeyError:
       counter[bytes] = 1

for key in sorted(counter.keys()):
    print '%s: %d,' % (repr(key),counter[key]),
print
</code>
--
Vernon


More information about the python-win32 mailing list