Scanning a file
jstroud at mbi.ucla.edu
Fri Oct 28 19:53:06 CEST 2005
On Friday 28 October 2005 06:29, Björn Lindström wrote:
> "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")
The "f" is not terribly unnecessary, because the part of the code you didn't
Which would be considered good practice.
UCLA-DOE Institute for Genomics and Proteomics
Los Angeles, CA 90095
More information about the Python-list