# sumfile2.py
# Written by Todd Wareham for CS 2500
"""
Given the name of a file of strings (all of which need not be integers) as 
 a command-line argument, computes and prints the number and total of 
 positive non-zero integers in this file.

This version is implemented using a for-loop, a continue-statement, and a
 try-except statement.
"""

import sys 

if len(sys.argv) != 2:
    print "usage: ", sys.argv[0], " filename"
    sys.exit(1)

sum = numPInt = 0

for line in file(sys.argv[1]):
    for num in line.split():
        try:
            if (int(num) <= 0): continue
            sum = sum + int(num)
            numPInt = numPInt + 1
        except ValueError:
            pass

print "sum, # +ve int = ", sum, ",", numPInt

