# get the filename and open it filename = raw_input("Filename: ") file = open(filename, "r") # initialize the counters total_lines = 0 total_chars = 0 for line in file: # clean any trailing whitespace off the string line = line.rstrip() # do the counting total_lines += 1 total_chars += len(line) print total_chars # summary output print "Total lines:", total_lines print "Total characters:", total_chars