''' This program does this: opens a file for reading opens another file for writing counts the fields in each input line, and writes that count to the output file ''' input_file_name = 'numbers.txt' output_file_name = 'numbers_counts.txt' in_handle = open(input_file_name, 'r') out_handle = open(output_file_name, 'w') lines = in_handle.readlines() for line in lines: fields = line.split() num_fields = len(fields) out_handle.write(str(num_fields) + '\n') in_handle.close() out_handle.close()