我查看了互联网上有关使用.csv模块的信息; 还有一些人突出了这个问题,但我还没有找到具体的解决方案.
目前,排序/写入/输出代码的工作范围是它将正确的数据输出到文件,但在正确的数据行之间留下空行.
只是为了给出以下代码的一些背景知识; 我必须只输出每个人的最后3个分数到文件中,我将使用"名称,类"对作为数据库的主键,即我将识别数据库的用户.变量'totalscore','难度','用户名'和'类'已在早期代码中定义(有很多,并且它并不完全相关,所以我没有包含它)
savescore = 0
savescore = totalscore * (difficulty + 2) #Multiplies their score out of 10 by difficulty + 2
print("You got " + str(totalscore) + " Out of ten and scored " + str(savescore) + " points" )
with open("Scoredatabase.csv","r") as f:
f=csv.reader(f)
NameClassScoreList = []
for line in f:
NameClassScoreList.append(line[0:5]) # Creates a list of all of the entries in the .csv file (List of lists) in the order Name,Class,Score,Score,Score
NameClassList = [] …Run Code Online (Sandbox Code Playgroud)