我正在制作一个愚蠢的小游戏,将你的分数保存在 highscores.txt 文件中。
我的问题是对线条进行排序。这是我到目前为止所拥有的。
也许python的字母数字排序器会有所帮助?谢谢。
import os.path
import string
def main():
#Check if the file exists
file_exists = os.path.exists("highscores.txt")
score = 500
name = "Nicholas"
#If the file doesn't exist, create one with the high scores format.
if file_exists == False:
f = open("highscores.txt", "w")
f.write('Guppies High Scores\n1000..........Name\n750..........Name\n600..........Name\n450..........Name\n300..........Name')
new_score = str(score) + ".........." + name
f = open("highscores.txt", "r+")
words = f.readlines()
print words
main()