Created
February 3, 2018 12:09
-
-
Save prl900/47690adadcafaabfd3c12e2bb722205e to your computer and use it in GitHub Desktop.
Python CSV parser sample code
This file contains hidden or 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
FILE_NAME = "CSVFile.csv" | |
def exists(name, persons): | |
for person in persons: | |
if name == person[0]: | |
return True | |
return False | |
def get_phone(name, persons): | |
for person in persons: | |
if name == person[0]: | |
return person[1] | |
return "" | |
with open(FILE_NAME) as f: | |
persons = f.readlines()[1:] | |
persons = [x.rstrip().split(',') for x in persons] | |
print len(persons) == 4 and exists('Bob', persons) and get_phone('Dave', persons) == "0400 001 123" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment