In a section of a game I am creating a user enters a username. The username and user's score are saved in an object which is pickled to an external file which has the other pickled score objects in it.
I then have a button on the UI that if clicked should display the Highest scores of all players in descending order.
I load in the file into a list with the code I found here .
Highscores = []
Highscores = pickle.load(open("Highscores.txt", "rb"))
I then use a bubble sort to sort the list of objects shown below.
def bubbleSort():
swapOccured = True
while swapOccured == True:
swapOccured = False
for i in Highscores:
if Highscores[i].score > Highscores[i + 1].score:
hold = Highscores[i + 1]
Highscore[i + 1] = Highscores[i]
Highscores[i] = Highscores[i + 1]
swapOccured = True
The error that is getting returned is
for index in Highscores:
TypeError: iteration over non-sequence
I have looked at other questions like this for example here but the error was that the program was looping through an object not looping through a list of objects. I'm pretty sure it's not the same error as the example, I think it could be with loading in a list of objects with pickle but I'm stuck.
Any help would be greatly appreciated.