I am reading in a .csv file similar to the following. Note that PhoneNumbers can contain multiple values delimited by the pipe character.
FirstName,LastName,PhoneNumbers
Bucky,Fuller,213.283.5555|714.345.5566
Stephen,Hawking,212.456.7897|312.345.6677|415.223.3423
Robert,Heinlein,562.457.8899
I am able to read in the .csv file and write out to a file using the following.
.....
dReader = csv.DictReader(open('employee_import.csv', 'rb'), delimiter=',', quotechar='`')
for row in dReader:
file.write("\t\t\t<PHONEBOOK>\n")
file.write("\t\t\t\t<LASTNAME>"+str(row.get('LastName'))+"</LASTNAME>\n")
file.write("\t\t\t\t<FIRSTNAME>"+str(row.get('FirstName'))+"</FIRSTNAME>\n")
file.write("\t\t\t\t<PHONENUM>"+str(row.get('PhoneNumbers'))+"</PHONENUM>\n")
file.write("\t\t\t<PHONEBOOK>\n")
.....
I was wondering if anyone had any ideas how I could iterate through the PhoneNumbers Key,Value pair so that I can separate out the multiple PhoneNumbers a person can have? Thank you.
Why not split the phone number field?