This is the code with comments and tabs shown:<br><br><br><br>
func db_import(csv_file,dict_to_append,DICT_HEADERS_LIST):#EDITED: In order to loop through keys of keys as noted in the EDITED section of the first post, EXTRA ARG is called DICT_HEADERS_LIST
tab->var file = File.new()<br> #creates a new Class instance. A var will store this reference as 'file'. (file is not a string)
tab->file.open(csv_file,file.READ) <br>#the file is read into memory. The .csv can now be manipulated with File methods.
<br>
tab->var is_header = true <br>#this bool will toggle to false once the while loop has run once.
<br>tab->var attributes_list = [] <br>#this list will store the first item of each column of the .csv
<br>tab->file.seek(0) <br>#this makes sure that the reader's cursor position (an invisible cursor) is at the first character.
<br>tab->var temp_dict = {} <br>#a temporary dictionary which will only live within a call of this func
<br>tab->while !file.eof_reached(): <br>#this says 'While the reader's invisible cursor is not on the last character in the .csv
<br>tab->tab->var line = file.get_csv_line() <br>#a variable called line will store an array of all of the Comma Separated Strings on one line of the .csv file
<br>tab->tab->if is_header == true: <br>#Is the bool is_header true?
<br>tab->tab->tab->attributes_list = line <br>#yes, it is, so set the pre-made array variable above the while loop to equal the first line (which is also an array)<br><br>tab->tab->tab->for item in attributes_list:<br>#EDITED: In order to loop through keys of keys #for each item in that array variable,<br><br>tab->tab->tab->tab->DICT_HEADERS_LIST.append(item)<br>#EDITED: In order to loop through keys of keys #append the list-as-arg with whatever column header is being iterated over.<br><br>tab->tab->tab->is_header = false <br>#the above loop will not continue because now is_header is false. You now have a list of header attributes which will be used as keys to locate the specific values entered below them in the .csv file.<br>
<br>tab->tab->else: <br>#the header list has been created and is_header is false, so continue below
<br>tab->tab->tab->for i in range(0,attributes_list.size()): <br>#for each index, from the smallest to largest possible value in the array
<br>tab->tab->tab->tab->temp_dict[attributes_list[i]] = line[i]<br>#create a key in the temp_dict variable that is named some item of the attribute_list i.e. the list of headers.<br>#which header is used is notated by the index. <br>#this newly created key will be defined i.e. have the value of an item in an array of strings i.e. the array of strings taken from a line in the .csv file.
<br>tab->tab->tab->dict_to_append[line[0]] = temp_dict <br>#our permanent dictionary which we want to create will have a key that is named to be the first item in every line but the first's first item
tab->tab->tab->temp_dict = {}<br> #Edited as of 8/26/2016 , temp dict has to be cleared or it will only contain the last value <br>tab->print(dict_to_append)