import sys # # Get the filename and open it # if (len(sys.argv) == 2): filename = sys.argv[1] # raw_input("Enter the name of the file: ") elif (len(sys.argv) == 1): filename = raw_input("Enter the name of the file: ") else: print "You should only provide one filename" sys.exit(-1) inf = open(filename, "r") # # read each number (one per line) and sum them # total = 0 line = inf.readline() while (line != ""): num = int(line) total = total + num line = inf.readline() inf.close() print "The total of all the numbers in",filename,"is",total