Hello again. This is the second part to my previous question. I've learned a bit about arrays, but the solution to this array problem still alludes me, so I thought I'd ask for help again here. Bottom line is, my instructor wants us to understand arrays (old skool). He says its like looking under the 'hood' of lists. So here's what I've got (below). Here's my array class that was given to me by him. I believe it was designed to mimic a 'restrictive list' to appear array-like. I've enclosed my .csv file and my instructor's directions. Right now all I want to do is populate the array with the info from the .csv file. "Step 1: Add a menu option to load students from a CSV file" (no problem). This should create an Array of Student objects which contain the relevant data."(problem) I figure I can figure out steps 2 and 3 on my own. At present I'm scouring You Tube for any information on arrays so I can teach myself.
ID,First Name,Last Name,Program,Start Date,Adv Last Name,Most Recent Term,GPA
104,Todd,Jeffries,B25590S,01/11/16,Willy,2017SU,3.9
047,George,Evans,B25590C,08/21/17,Willy,2017FA,3.1
257,Jennifer,Reynolds,B25590N,01/17/17,Willy,2017FA,2.9
1707,Twan,Jelens,B25590C,08/15/16,Smith,2017SP,3.3
1865,Paul,Knapp,B25590S,08/15/16,Willy,2018FA,3.4
2104,Phyllis,Cashwell,B25590C,08/15/16,Smith,2017SP,3.25
2214,Beeman,Ciani,B25590N,08/15/16,Willy,2017SP,2.9
2215,Gertrude,Carmella,B25590C,08/15/16,Willy,2018SP,3.8
2838,Morty,Balzano,B25590C,05/30/17,Willy,2018FA,2.7
3104,Steve,Abrams,B25590S,08/21/17,Willy,2018FA,3.15
class Array(object): """Represents an array.""" def __init__(self, capacity, fillValue = None): """Capacity is the static size of the array. fillValue is placed at each position.""" self._items = list() for count in range(capacity): self._items.append(fillValue) def __len__(self): """-> The capacity of the array.""" return len(self._items) def __str__(self): """-> The string representation of the array.""" return str(self._items) def __iter__(self): """Supports iteration over a view of an array.""" return iter(self._items) def __getitem__(self, index): """Subscript operator for access at index.""" return self._items[index] def __setitem__(self, index, newItem): """Subscript operator for replacement at index.""" self._items[index] = newItemThis is my code. I'm trying to populate an array with the data from a .csv file (bottom of page)
#a = Array(8) lyst1 = [] with open("student_advisees_testdata.csv",'r') as csv_file: csv_reader = csv.reader(csv_file) next(csv_reader) for line in csv_file: line = line.split(',') index = 0 for word in line: lyst2 = [] lyst2.append(word) lyst1.append(lyst2) a = Array(8,lyst1) print(a).csv file:
ID,First Name,Last Name,Program,Start Date,Adv Last Name,Most Recent Term,GPA
104,Todd,Jeffries,B25590S,01/11/16,Willy,2017SU,3.9
047,George,Evans,B25590C,08/21/17,Willy,2017FA,3.1
257,Jennifer,Reynolds,B25590N,01/17/17,Willy,2017FA,2.9
1707,Twan,Jelens,B25590C,08/15/16,Smith,2017SP,3.3
1865,Paul,Knapp,B25590S,08/15/16,Willy,2018FA,3.4
2104,Phyllis,Cashwell,B25590C,08/15/16,Smith,2017SP,3.25
2214,Beeman,Ciani,B25590N,08/15/16,Willy,2017SP,2.9
2215,Gertrude,Carmella,B25590C,08/15/16,Willy,2018SP,3.8
2838,Morty,Balzano,B25590C,05/30/17,Willy,2018FA,2.7
3104,Steve,Abrams,B25590S,08/21/17,Willy,2018FA,3.15