Lots of Contacts

Telephone Book 1

Retrieve the file us-500-2.csv from the HSAPPS H: drive under Data.  Save it to the same location as your AddressBook program.

Add the following two methods to your AddressBook class.  It will load contacts to our address book from a .csv file.

	# *****************************************************
	def addContact(self, newcontact):
			self.contactlist.append(newcontact)

	# *****************************************************
	def importFromCSVFile(self, filename):
		f = open(filename,'r')
		l = 0
		for line in f:
			cells = line.strip().split(',')
			l += 1
			self.addContact(Contact(cells[0].strip(),cells[1].strip(),
				'nickname',cells[8].strip(),cells[9].strip(),
				cells[10].strip(),'PutPhotoHere',cells[3].strip(),
				cells[4].strip(),cells[6].strip(),cells[7].strip()))
		f.close()
		print str(l) + " contacts added to the AddressBook."

You can test the function by adding the following lines to the bottom of your main program:

# Create an AddressBook object
myAddressBook = AddressBook('MyAddressBook')
myAddressBook.importFromCSVFile('us-500-2.csv')
print myAddressBook.contactlist[0].firstname