Skip to content

Instantly share code, notes, and snippets.

@cigrainger
Created December 14, 2013 22:04
Show Gist options
  • Save cigrainger/7965506 to your computer and use it in GitHub Desktop.
Save cigrainger/7965506 to your computer and use it in GitHub Desktop.
import csv
f = open('students.csv').read()
while f.split('\n')[0] != 'name,email':
morecsv = raw_input("This does not look like the correct file. Would you like to see more? y/n?")
while morecsv != 'y' or 'n':
morecsv = raw_input("The prompt was y/n only. Would you like to see more? y/n?")
if morecsv == 'y':
print f.split('\n')[:10]
newcsv = raw_input("Would you like to overwrite this file to create the student list? y/n?")
while newcsv != 'y' or 'n':
newcsv = raw_input("y/n only. Would you like to overwrite this file to create the student list?")
if newcsv == 'y':
f.truncate()
f.write('name,email')
if newcsv == 'n':
return 'Okay. Goodbye.'
elif morecsv == 'n':
return 'Okay. Goodbye.'
header = f.split('\n')[0]
students = {str(header.split(',')[0]):[]}
for i in range(1,len(header.split(','))):
students[str(header.split(',')[i])] = []
if f.split('\n') > 1:
rows = f.split('\n')[1:]
for i in range(0,len(header.split(','))):
students[str(header.split(',')[i])] = [j.split(',', 1)[i] for j in rows]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment