简体   繁体   中英

Transferring list from one class method to another

So in a class that I have, I create a list from information gathered in a different list line by line, and so far that has gone smoothly. My issue is that with this newly made list, I need to utilize a different method in the same class in order to print the list's information in a structured manner. I am unsure of exactly how to get the new list from one method to another so that I can begin the printing process. In my main program, that utilizes a dictionary (string value as key, class object as value) to refer to the class methods, I have the input of

playerDict[nameChoice].calc(basicList)

which takes me to the method for the given player, and then compiles the list. The two methods are as follows

    def calc(self, sublist):
    '''calculate a passer rating for one sub-list year in the info list'''

    ratingList = []
    count = 0
    for line in self.info:
        C = ((((int(line[3]) / int(line[4]))*100) - 30)/20)
        if C > 2.375:
            C = 2.375
        Y = (((int(line[5]) / int(line[4])) - 3) * .25)
        if Y > 2.375:
            Y = 2.375
        T = (((int(line[6])) / int(line[4])) * 20)
        if T > 2.375:
            T = 2.375
        I = 2.375 - ((int(line[7])/int(line[4])) * 25)
        ratingtop = (C + Y + T + I)
        ratingbot = 6
        yearRating = float((ratingtop / ratingbot) * 100)
        ratingList.append([self.info[count][0], self.info[count][2], yearRating])
        print(ratingList)
        count += 1
    ratingList.sort()
    print(ratingList)
    print_ratings = self.printInfo
    return ratingList

def printInfo(self):
    '''print individual year information about this player including each years passer rating. The list should be in year order. Use calc to assist.'''

So the list I need in the printInfo method is ratingList. In my main program, I have invoked the two separately, using playerDict[nameChoice].calc(basicList) and playerDict[nameChoice].printInfo() , but I need to find a way to get the ratingList into the printInfo method in order to print out the information in the list in the specified manner. How would I go about doing this? I dont have printInfo completed yet but that part will come easily once I am capable of utilizing the list in the method.

def printInfo(self, basicList):
    ratingList = self.calc(basicList)
    ...

Note that printInfo needs the list as well.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM