Very new python programmer here.
I'm trying to take a list of people's names and information (in this case, baseball players) and create a different object for each player with attributes based on the other information in those strings. So for example, I have the following list of people stored in a list called my_players (of course, my actual list of players is much longer):
SS Derek_Jeter Yankees
P Johan_Santana Mets
C Ivan_Rodriguez Tigers
I'd like to create objects of the class Player, where Player is defined as:
class Player():
def __init__(self,full_name,pos,team_name):
self.name = full_name
self.position = pos
self.team = team_name
But I don't want to have to manually create each object, I want to use a for loop that, for each string in my_players, uses the second word in the string to be the name of the object, then the three parts of the string to be the attributes. That is, I'll want one object called Derek_Jeter with the attributes Derek_Jeter, SS, Yankees, and another object called Johan_Santana, and another called Ivan_Rodriguez, but I don't want to type each of those object names into my code. How can I create objects this way?