PY4E: dict() and loops error message

I’m stuck on an error message I’m r eceiving in an exercise to open a file and file the largest word in it.
I get this error message:
AttributeError: '_io.TextIOWrapper' object has no attribute 'split'

My code is below:

#input open
name = input("Enter file name...")
file  = open(name)


#input into dictionary
counts = dict()
for line in file:
    words = file.split()
    for word in words:
        counts[word] = counts.get(word, 0) + 1


#finding the biggest word
bigCount = None
bigWord = None
for word, count in counts.items():
    if bigCount is None or count > bigCount:
        bigCount = count
        bigWord = word
print(bigWord, bigCount)

Where is my error? Everything seems logical AND it seems to match the example code in the lesson which it is patterned after.

What am I missing?

Are you not supposed to call split on line?

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.