write to csv python dictionary dict.write

import csv

with open('names.csv', 'w', newline='', encoding='utf-8') as csvfile:
    fieldnames = ['first_name', 'last_name']
    writer = csv.DictWriter(csvfile, fieldnames=fieldnames)

    writer.writeheader()
    writer.writerow(
        {
            'first_name': 'Padme',
            'last_name': 'Amidala'
        }
    )
SNAPPED!

SNAPPED!

Comments

Popular posts from this blog

Append to a json file python

Setup Mailhog mail server on Ubuntu