CSV写入器停在一行

  • 本文关键字:一行 CSV python csv
  • 更新时间 :
  • 英文 :


如何将所有数据写入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)

相关内容

  • 没有找到相关文章

最新更新