reading a file, taking file line content, then using content as parameters for class method definitions Python
Question: What I am trying to do here is read a line of a file. If the content in the
file meets the correct criteria execute one of the definitions in my class.
The thing is I have no clue on what kind of code I need for this.

here is what I have so far:

    
    
    class Score:
    # class to hold a running score, from object to parameter
    # also to set number of scores that contribute to total of 1
    
        def __init__(self):
    #initalizes the running score and score input accumilators
            self.runScore = 0
            self.scoreInputs = 0
    
        def updateOne (self, amount):
    #updates running score by amount and Score input by 1
            self.runScore += amount
            self.scoreInputs += 1
    
        def updateMany(self,lst):
    #updates running score by the sum of the list and score inputs by the amount of
    # number of items in the list
            self.runScore += sum(lst)
            self.scoreInputs += len(lst)
    
        def get(self):
    #returns the current score based on total amount scored
            print(self.runScore)
    
        def average(self):
    #returns the average of the scores that have contributed to the total socre
            print(self.runScore // self.scoreInputs)
    
    def processScores (file):
        with open('file','r') as f:
        for line in f:
            line
    

The Idea is that processScores will be ran. As the code reads the file line by
line if it finds a certian marker in the line example G then the next line it
reads shall be input into the def updateOne. But thats just an example.

Anyideas on what I can do better?

Thank you


Answer: It would be better to pass a Score instance to the function and have it update
it as it reads the file.

    
    
    def processScores(file, score):
        with open(file, 'r') as f:
            for line in f:
                if line[0] == 'G':
                    amount = int(next(f)) # read next line & convert to integer
                    score.UpdateOne(amount)
    

However it would be even better than that to make it a method to provide
better [encapsulation](http://en.wikipedia.org/wiki/Encapsulation_%28object-
oriented_programming%29), or bundling of data and functions within it -- which
is an important principle of object-oriented programming. This way if you
change what information is stored in instances of class, how it updating is
done, or how the data file formatted, you have to make changes in one place.

    
    
        def processScores(self, file):
            with open(file, 'r') as f:
                for line in f:
                    if line[0] == 'G':
                        amount = int(next(f)) # read next line & convert to integer
                        self.UpdateOne(amount)
    

