''' This program does this: opens a file, and counts the number of fields in the file (fields are separate by spaces) prints the count ''' file_name = 'numbers.txt' handle = open(file_name, 'r') lines = handle.readlines() count = 0 for line in lines: fields = line.split() count += len(fields) print 'The file', file_name, 'has', count, 'fields'