def write_data_to_csv(csv_name, people, countries):
""" Loop through the list of people and write them to a csv.
Args:
csv_name (str): Name of the file to write results to.
people (list): List of instantiated ``Person`` objects.
countries (list): List of strings that represent countries.
"""
with open(csv_name, 'w') as outfile:
writer = csv.writer(outfile)
columns = ['name'] + countries
writer.writerow(columns)
for person in people:
person_row = [person.name] + [
getattr(person, country, 0) for country in countries
]
writer.writerow(person_row)
eurovision.py 文件源码
python
阅读 33
收藏 0
点赞 0
评论 0
评论列表
文章目录