如何将所有数据写入CSV?目前,这是创建一个完整的行。但并没有继续前进。我试过写作。行,我尝试了"卡片"
Cards = Card.where(q='set.name:generations supertype:pokemon')
for card in Cards:
card = (card.name, card.types, card.supertype, card.subtypes, card.number, card.rarity, card.nationalPokedexNumbers, card.id, card.set.name, card.set.series)
rows = card
with open ('pokemontest3.csv', 'w', newline='', encoding='utf-8') as csv_file:
csvwriter = csv.writer(csv_file)
csvwriter.writerow(rows)
在for
循环中继续覆盖rows
。当它完成时,只有最后一张卡在rows
中。如果在创建了写入器之后才运行循环,则可以随写随写。
with open ('pokemontest3.csv', 'w', newline='', encoding='utf-8') as csv_file:
csvwriter = csv.writer(csv_file)
Cards = Card.where(q='set.name:generations supertype:pokemon')
for card in Cards:
card = (card.name, card.types, card.supertype, card.subtypes, card.number, card.rarity, card.nationalPokedexNumbers, card.id, card.set.name, card.set.series)
csvwriter.writerow(card)