Scanning a file

Björn Lindström bkhl at
Fri Oct 28 15:29:46 CEST 2005

"pinkfloydhomer at" <pinkfloydhomer at> writes:

> f = open("filename", "rb")
> s =
> sub = "\x00\x00\x01\x00"
> count = s.count(sub)
> print count

That's a lot of lines. This is a bit off topic, but I just can't stand
unnecessary local variables.

print file("filename", "rb").read().count("\x00\x00\x01\x00")

Björn Lindström <bkhl at>
Student of computational linguistics, Uppsala University, Sweden

More information about the Python-list mailing list