需要帮助着写入文件按字母顺序的Python写为.txt字母
class_name = "class 1.txt" #adds '.txt' to the end of the file so it can be used to create a file under the name a user specifies
with open(class_name , 'r+') as file:
name = (name)
file.write(str(name + " : ")) #writes the information to the file
file.write(str(score))
file.write('\n')
lineList = file.readlines()
for line in sorted(lineList):
print(line.rstrip())
什么是名称和分数? –