Skip to content

Instantly share code, notes, and snippets.

@8bitben
Created April 30, 2019 17:44
Show Gist options
  • Save 8bitben/b69752bea220edb8acc9e5c1fb17e175 to your computer and use it in GitHub Desktop.
Save 8bitben/b69752bea220edb8acc9e5c1fb17e175 to your computer and use it in GitHub Desktop.
python-csv.py
'''
https://docs.python.org/3/library/csv.html
'''
import csv #import the required libraries
#open the file and assign it an identifier
with open('people.csv') as people:
#create a Dictionary Reader and pass the open file
my_csv_file = csv.DictReader(people)
#iterate the reader
for row in my_csv_file:
#preform actions with row content
print('My name is {}'.format(row['name']))
print('I am {} years old'.format(row['age']))
print('I live in {}'.format(row['location']))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment