title: Python Reading and using data from file
body: <p>I am currently trying to save scores from a quiz to an excel sheet which allows the user to read the files, but how can I use their save data to only save the last 3 scores of a user. I understand this would mean reading from the file to see the scores and then making it read how many tries the user has had etc. but I can't quite figure out how to make it so the program will only save the last 3 scores from that user or their 3 highest scores. Thank you.                </p>
  
  <pre><code>            if pclass == 1:
                  inFile = open("ascores.csv", 'a')
                  inFile.write("\n" + pname + ", " + str(correct) + ", " + str(round(etime, 1)))
                  inFile.close()
                  inFile = open("ascores.csv", 'r')
                  print(inFile.read())
              elif pclass == 2:
                  inFile = open("bscores.csv", 'a')
                  inFile.write("\n" + pname + ", " + str(correct) + ", " + str(round(etime, 1)))
                  inFile.close()
                  inFile = open("bscores.csv", 'r')
                  print(inFile.read())
              elif pclass == 3:
                  inFile = open("cscores.csv", 'a')
                  inFile.write("\n" + pname + ", " + str(correct) + ", " + str(round(etime, 1)))
                  inFile.close()
                  inFile = open("cscores.csv", 'r')
                  print(inFile.read(sorted(reader, key=lambda row: int(row[0]))))
              else:
                  print("Sorry we can not save your data as the class you entered is 1, 2 or 3.")
  </code></pre>