root/hodgestar/PythonCode/SmallScripts/cnt.py

Revision 408, 305 bytes (checked in by simon, 4 years ago)

Small script for summing word counts in a file with lines like: <name> <number>.

  • Property svn:mime-type set to text/python-source
  • Property svn:eol-style set to native
Line 
1import sys
2
3f = file(sys.argv[1])
4
5iCnt = 0
6for i, line in enumerate(f):
7    aParts = line.split(':')
8    if len(aParts) == 2:
9        try:
10            iCnt += int(aParts[1].strip())
11        except ValueError, e:
12            logging.warn("Failed to parse count on line %d : %s" % (i+1, line))
13
14print iCnt
Note: See TracBrowser for help on using the browser.