我正在制作一个愚蠢的小游戏,将您的分数保存在highscores.txt文件中。用Python中的整数和文本对字符串排序
我的问题是整理线条。这是迄今为止我所拥有的。
也许一个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()
尝试使用数组 – 2009-10-16 01:08:36