Scanning a file

Björn Lindström bkhl at stp.lingfil.uu.se
Fri Oct 28 15:29:46 CEST 2005


"pinkfloydhomer at gmail.com" <pinkfloydhomer at gmail.com> writes:

> f = open("filename", "rb")
> s = f.read()
> 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 stp.lingfil.uu.se>
Student of computational linguistics, Uppsala University, Sweden



More information about the Python-list mailing list