Re: [python-win32] print file byte contents distribution

2011-03-04 Thread Tim Roberts
Ghostly wrote: > Thanks guys for your input > > As I need this for larger files (couple of tens even hundrets of MB) I > tested your suggestion and it seems that dict method is fastest. I decided to find out, so I ran "timeit" on both schemes using a 2MB file. The two methods are within 1% of eac

Re: [python-win32] print file byte contents distribution

2011-03-04 Thread Ghostly
Thanks guys for your input As I need this for larger files (couple of tens even hundrets of MB) I tested your suggestion and it seems that dict method is fastest. I ended with this: import sys try: counter = {} for bytes in open(sys.argv[1], "rb").read():

Re: [python-win32] print file byte contents distribution

2011-03-04 Thread Tim Roberts
Vernon Cole wrote: > 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. > > counter = {} > > for bytes in open('c:\\temp\\16.jpg', "rb").read(): >try: >counter[bytes] += 1 >

Re: [python-win32] print file byte contents distribution

2011-03-04 Thread Vernon Cole
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. counter = {} for bytes in open('c:\\temp\\16.jpg', "rb").read(): try: counter[bytes] += 1 except KeyError: counter[bytes

[python-win32] print file byte contents distribution

2011-03-04 Thread Ghostly
Hi, As I don't see any CLI tool other then hex editor, I thought on writing small script that will display byte distribution from file content So I thought on this: - counter = {} for bytes in open('c:\\temp\\bin.dat', "rb").read(): counter[bytes] = counter.get(b