嗨,我有一个奇怪的问题,我的排行榜在Python。我有球员得分变量被写入文件,这通常是工作,但有时它只是写0,而不是他们得分的数字。这只是偶尔发生,但需要修正。我想这和设置playerscore=0之前使用的延迟有关,但我不确定要更改什么来修复它。代码如下。在
with open('Leaderboard.csv', 'a', newline='') as filepath:
a = csv.writer(filepath, delimiter=',')
data = [[PlayerScore, player_name]]
a.writerows(data)
f = open('Leaderboard.csv')
csv_f = csv.reader(f)
name = []
for row in csv_f:
name.append(row)
f.close()
print(PlayerScore)
# set PlayerScore to 0
pygame.time.delay(100)
PlayerScore = 0
试试这个:
如果要正确排序,不要忘记将分数从字符串转换为int(或float),否则它们将按字典顺序排序。在
相关问题 更多 >
编程相关推荐