I am trying to sort a text file in numerical order, from largest at the top of the file, to lowest at the bottom of the file. Each line in the file only contains one number. I want to know how I can sort the text file every time run the code so that the numbers are always sorted. This is then used so I can then make a leaderboard.
savefile.write("\n")
savefile.write(User1)
savefile.write(" Got a total score of ")
savefile.write(Total1)
savefile.close()
savefile = open("Winnersnum.txt","a")
savefile.write("\n")
savefile.write(Total1)
savefile.close()
All the numbers are saved in winnersnum.txt and if anyone could tell me how to sort it that would be great. (I know I can sort it using variables and reading but I don't want to have to make a bunch of lines to read with a bunch of variables)
Here is an example of the Winnersnum text file: Picture of file