def main(): splash() wordTotal = 0 longestWord = 0 fin = open("constitu.txt") for line in fin: #n = fin.readline() wordLine = line.split() #word = wordLine.split() wordTotal += len(wordLine) #if len(word) >= 15: #longestWord += 1 #print word print "This constitution has ",wordTotal, " words." def splash(): print "This program is going to read the Constitution " \ + "of the United States of America " \ + "and determine the length and longest word in it.\n" main()
I'm trying to read the constitution from a file I have in the same folder as this program. the file name is constitu.txt
whenever i add in line "n = fin.readline()", i get an Mixed Iteration variable error:
File "C:\COP1000\HW07-CLD (Unfinished).py", line 13, in main
text = fin.readline()
ValueError: Mixing iteration and read methods would lose data
when i take that line out, i get no errors but my program will not count the words in my .txt file.
Any help would be appreciated, i'm using python v2.7