[英]Python - Exported data to CSV in loop only saves last line of output
我在变量 gameList 中有一个游戏名称字典。 从那里我可以成功打印每个游戏名称,但是当尝试将列表中的每个游戏保存为 CSV 时,它只会保存输出的最后一个游戏名称,而不是整个列表。
for i in gameList:
#print(games[i]['name'])
csvGames = games[i]['name']
with open('exportedGamesList.csv', 'w', encoding='utf-8') as csvfile:
for line in csvGames:
csvfile.write(line)
任何援助将不胜感激 :)
您应该将with open('exportedGamesList.csv', 'a', encoding='utf-8') as csvfile:
附加到文件中with open('exportedGamesList.csv', 'a', encoding='utf-8') as csvfile:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.