Question about attribute error


I am writing a code that reads movie reviews from a separate text file, learns from that, and then the user inputs a review. The code then uses what it learned to rate the users review.The error is "builtins.AttributeError: 'dict' object has no attribute 'has_key'" it's probably a simple error but I can not figure out how to fix it. The error appears on line 34.

import re
import string
class Review:
    def __init__(self,keyword,averageScore=0,occurences=0):
    def getWord(self):
        return self.keyword
    def getAvergaeScore(self):
        return self.averageScore
    def getOccurences(self):
        return self.occurences
    def addNewScore(self, newScore):
        oldScoreSum = self.averageScore * self.occurences
        self.occurences = self.occurences + 1
        self.average = (oldScore + newScore) / (self.occurences)
    def printWordStatistic(self):
        print ("Words       : " , self.keyword)
        print ("Occurences  : " , self.occurences)
        print ("Average Score : " , self.occurences, "\n\n")
wordDictionary = {}
fileInstance= open("movieReviews.txt" , "r")
fileText =
reviewSplits = fileText.split("movieReviews")
for review in reviewSplits:
    lineSplits = review.split("\n")
    score = str(lineSplits[0].strip())
    for i in range(1,len(lineSplits)):
        wordSplits = re.split("\t| ", lineSplits[i])
    for word in wordSplits:
        #if word = "" 
         #   continue
        if wordDictionary.has_key(word):
            wordStatsitic = wordDictionary.geet(word)
            wordStatsitic = addNewScore(score)
            wordStatsitic = WordStatitic(word, score, 1)
            wordDictionary = [word]=wordStatistic
    def printAllWordStatisitc(wordDictionary):
        for wordStatsitic in wordDictionary.values():
    def calculateAverageOfReview(review):
        review.replace("\t", " ")
        review.replace("\t", " ")
        wordSplits = review.split(" ")
        averageScore = 0.0
        totalCount = 0;
        for word in wordSplits:
            if wordDictionary.has_key(word):
                averageScore+= wordDictionary.get(word).getAverageScore()
                totalCount = totalCount + 1
            if totalCount != 0 :
                returnaverageScore / totalCount
            return -1
    while (True):
        print ("\nEnter a movie review: ")
        while True:
            line =input()
        if averageScore !=1:
            if averageScore >= 2.50:
                print("Postitive review")
                print("Negative review")


That's pretty much plain english, what's the problem? Would you argue that it does? What's the motivation for that you would be able to do that? Or if you agree that you might not be able to do that, then at least you've got a very specific action that you can look up how to do


What version of Python are you using?


I am using python 3.6.0


Make sure you use the dict documentation for that version of Python.


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