Last active
September 7, 2016 22:16
-
-
Save palewire/23765d7349fb40c6edded67f8effea4b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
first_name | last_name | |
---|---|---|
ben | welsh | |
peter | jamison |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import csv | |
class Person(object): | |
""" | |
A human. | |
""" | |
def __init__(self, first_name, last_name): | |
self.first_name = first_name | |
self.last_name = last_name | |
def __str__(self): | |
return "{} {}".format(self.first_name, self.last_name) | |
# Open the file | |
file_obj = open("./data.csv", "r") | |
# Have the csv module parse it | |
data_list = csv.DictReader(file_obj) | |
# Create an empty list for the person objects | |
person_list = [] | |
# Loop through the csv data | |
for row in data_list: | |
# Create a new person object | |
person_obj = Person(row['first_name'], row['last_name']) | |
# Add it to our object list | |
person_list.append(person_obj) | |
# Loop through that object list | |
for obj in person_list: | |
# Do stuff, like print it out. | |
print(obj) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment