# # Compute the sum of some numbers in a file # import sys # # Read the name of the file from the user # if len(sys.argv) == 2: fname = sys.argv[1] else: print("Usage: python", sys.argv[0], " ") quit() # # Open the file for reading # inf = open(fname, "r") # # Sum the values in the file # total = 0 line = inf.readline() while line != "": line = line.rstrip() print("Adding", line, "to the total...") total = total + int(line) print("Now the total is", total) line = inf.readline() # # Close the file # inf.close() # # Display the result # print("The total of those values is", total)