I have a Club class and a Player Class. The player class has an attribute Fav.clubs which will have unique club values. So the user is supposed to enter various club names. Based on the club names I must retrieve those club objects and establish the relationship that this particular player has this Fav.clubs.
The attribute Fav.clubs in Player class should store the names of Club. Now what I have to do is, take input from user about Fav.clubs (a list). After that traverse each element in the list and access the string name to find the corresponding club object and then store that object instance in Player class.
Store all clubs in a dictionary called
all_clubs. The key should be the club-name and the value the club object itself. Then you can doall_clubs[clubname]to retrieve the club object for a given name.The player might have an attribute
club_nameswhich is the list of the unique names you described and a propertyclubswhich might look like this:Alternatively, it might also be a good idea to use a ORM tool like sqlalchemy and a simple file-based or in-memory sqlite database. Then you have the power of SQL and a extremely good relational mapping. But if you are new to Python, I wouldn’t use something like that, because sqlalchemy is quite a complex topic and the mapping uses some python magic in the background, which you might not understand at the beginning. Therefore, I would suggest the first method.