在Python中被阻止关闭文件

在Python中被阻止关闭文件,python,file,Python,File,我正在尝试将2D数组中的分数放入一个文件中,并将它们按降序排列,最高分数将放入一个文本文件中,以便读取 def highScoresList(player,score): length = len(winners) winners.append("") winners.insert(length, player) winners.insert(length, score) if length == 0: length = length

我正在尝试将2D数组中的分数放入一个文件中,并将它们按降序排列,最高分数将放入一个文本文件中,以便读取

def highScoresList(player,score):
    length = len(winners)
    winners.append("")
    winners.insert(length, player)
    winners.insert(length, score)
    if length == 0:
        length = length
    else:
        for x in range (0,length):
            if winners[[x][1]] < winners[[x+1][1]]:
                temp = winners[x]
                winners[x] = winners[x+1]
                winners[x+1] = temp
                length += 1
if length <= 5:
    count = len(winners)
    if count < 5:
        for x in winners:
            high_scores = open("diceScores.txt","w")
            high_scores.write("",winners[[x][0]," - ",winners[[x][1]],""]
            **high_scores.close()** # Invalid Syntax
        high_scores = open("diceScores.txt","r")
        print(high_scores.read())
        high_scores.close()
    else:
        high_scores = open("diceScores.txt","a")
        for x in range (0,4):
            high_scores.write("",winners[[x][0]," - ",winners[[x][1]],""]
            high_scores.close()
        high_scores = open("diceScores.txt","r")
        print(high_scores.read())
        high_scores.close()
def高分列表(玩家,分数):
长度=长度(优胜者)
获胜者。附加(“”)
优胜者。插入(长度、球员)
优胜者。插入(长度、分数)
如果长度==0:
长度=长度
其他:
对于范围内的x(0,长度):
如果获胜者[[x][1]<获胜者[[x+1][1]]:
温度=优胜者[x]
优胜者[x]=优胜者[x+1]
优胜者[x+1]=临时
长度+=1

如果长度在第7行。我能做些什么来修复它?

问题是
close
之前的行中缺少一个右括号。应该是:

high_scores.write("",winners[[x][0]," - ",winners[[x][1]],""])

问题是
close
之前的行缺少右括号。应该是:

high_scores.write("",winners[[x][0]," - ",winners[[x][1]],""])

用包围线显示实际误差会很有帮助。用包围线显示实际误差会很有帮助。