f = open(filename)lines = f.readlines()f.close()print "%s has %d lines." % (filename, len(lines))
. . The problem with this approach is that you need to load the *whole* file into memory (as a list) to count its lenths. A better approach would be something like...f=open(r'file.txt', 'r');lines=sum(1 for line in f)
Post a Comment
Tell me when this blog is updated
what is this?
1 comment:
. . The problem with this approach is that you need to load the *whole* file into memory (as a list) to count its lenths. A better approach would be something like...
f=open(r'file.txt', 'r');
lines=sum(1 for line in f)
Post a Comment