Scanning a file
pinkfloydhomer at gmail.com
pinkfloydhomer at gmail.com
Fri Oct 28 09:22:11 EDT 2005
I'm now down to:
f = open("filename", "rb")
s = f.read()
sub = "\x00\x00\x01\x00"
count = s.count(sub)
print count
Which is quite fast. The only problems is that the file might be huge.
I really have no need for reading the entire file into a string as I am
doing here. All I want is to count occurences this substring. Can I
somehow count occurences in a file without reading it into a string
first?
/David
More information about the Python-list
mailing list