I found this question in a textbook to write code to count the number of lines of program by running it.
This is what I have:
import commands,os,sys
def count_lines(modul):
cmd="wc -l " + modul +" | awk '{print $1}'"
return commands.getoutput(cmd)
if __name__=='__main__':
print count_lines(sys.modules[__name__].__file__)
It seems to work;but I am not sure if this the right way to do. I thought this is simpler.
wc -l "file" | awk '{print $1}'will work without python.C. correct me if I am wrong..?