Line Counter
I use this script occasionally to check how much code I've written so far :)
So, here I'm using os.walk method which is basically an iterator that returns a triplet (path, directories, files) on each iteration. Method "walk" is doing a deep first search of the filesystem recursively (by default, can be turned off by a parameter topdown=False) and basically I just open every file and read lines (tho' I can't stress how much this code can be faster, smarter etc - this is the point of scripts - keep it simple, stupid).
#!/usr/bin/env python
import os
tot = 0
for path,b,c in os.walk("."):
mc = 0
for f in [each for each in c if each.endswith(".java")]:
fd = open(os.path.join(path,f))
for each in fd:
mc += 1
fd.close()
print "In %s\t: %d lines." % (path, mc)
tot += mc
print "Total: %d lines!" % (tot,)
There are currently no items in this folder.

