好的,所以我创建了一个模块并将其导入到我的主程序中。我想我仍在尝试理解类,但我不确定如何将我的数据实际输入到我的类中。这是在 Python 3 中。这是模块:
class Movie:
    def __init__(self, Title = '', Ratings = []):
        self.Movie = Title
        self.Ratings = Ratings
        self.TotalRatings = 0
        self.minusFive = 0
        self.minusThree = 0 
        self.one = 0
        self.three = 0
        self.five = 0
        self.ValidRatings = [-5,-3,1,3,5]
    def __str__(self):
        return '{0} has {1} total ratings with an average rating of {3}.'.format(self.title, self.totalRatings, self.AvgRating)
    def __repr__(self):
        return self.__str__()
    def AddRating(self, rating):
        for num in self.Ratings:
            if num in self.ValidRatings:
                self.totalRatings += 1 
            else:
                continue
    def AvgRating(self):
        return sum (self.totalRatings)/len(self.totalRatings)
下面是我的主程序的开始:
import Movie
def ReadFile(FileName):
    F = open(FileName)
    return F.readlines()
File = ReadFile('Ratings.txt') 
File2 = open('Prog5Titles.txt').read()       #open movie titles file
movie1 = Movie("The Avengers", [5,5,5])     #this is just a sample to help me understand
当我运行它时,我收到错误消息:'module' object is not callable。谁能帮我理解如何正确输入我的数据?