Skip to content

Instantly share code, notes, and snippets.

@prl900
Created February 3, 2018 12:09
Show Gist options
  • Save prl900/47690adadcafaabfd3c12e2bb722205e to your computer and use it in GitHub Desktop.
Save prl900/47690adadcafaabfd3c12e2bb722205e to your computer and use it in GitHub Desktop.
Python CSV parser sample code
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