def dataReader() : """This function will work to read through the data in the file and create the appropriate list of information using that data""" import string # Open the data file for reading file = open("rushers.csv", 'r') # Create an empty dictionary to store the information of the payer to players = {} # Read through each line in the file and throw away the column header # information line = file.readline().strip() line = file.readline().strip() while line != '' : # Strip away the extraneous punctuation and split the line at the commas newLine = line.strip(string.punctuation) newLine = line.split(',') # Create the players name and create a Player object passing the first # and last names as arguments first = newLine[0] last = newLine[1] playerObject = Player(first, last) name = playerObject.returnName() # Check to see if the player is already in the dictionary and if not add # him with his name as the key and the player object as the value if name not in players : players[name] = playerObject # Call the update function Player.update(players[name], newLine[2], newLine[3], newLine[13], \ newLine[5], newLine[6], newLine[7], newLine[10]) line = file.readline().strip() # Close the file file.close() # Create an empty list and append the values to it playerList = [] for val in players.values(): playerList.append(val) playerList.sort() # Print out the results for elem in playerList: print(elem) return players
def dict_builder(passer_list): """ builds a dictionary with names as keys and Player objects as values""" #create player dictionary player_dict = {} for player in passer_list: # creates the Player object using the names name = Player(player[0], player[1]) if Player.returnName(name) in player_dict: # calls update to update the information in self.info player_dict[Player.returnName(name)].update(player[3], player[4], \ player[6], player[7], player[8], player[9], player[12]) else: # if the name is not already in dictionary it creates an entry player_dict[Player.returnName(name)] = name # enters the first dictionary entry into the list player_dict[Player.returnName(name)].update(player[3], player[4], \ player[6], player[7], player[8], player[9], player[12]) return player_dict