dear fellow Python enthusiasts, let's say I have a dictionary of keys and values obtained from a form submitted by a user. For each submitted form I will create the Application and Candidate classes, and I want to be able to call Application(Candidate(**submitted_data)).display() to create an html representation of the user submitted data. Depending on the applicant's preferences and location, the number of fields on the form, and thus the size of this dictionary, is variable, and not all fields are required. I seem to recall a setargs function in Python that would take any argument passed into a class and set that argument as a member variable in a class. A Google search turned up no such construct, so here I am asking you, is there a way for me to create a class that accepts a dictionary of submitted data and uses each key ad value to create a corresponding member variable ? The current way I do this is with a very long argument list, and line by line:
<br><br>class Candidate(object):<br> def __init__(self, full_name, address_line_1, city, postal_code, email, desired_program, telephone=None, disabled=None, can_receive_media=None, media_sent_to=None, ...):<br>
self.full_name = full_name<br> self.address_line_1 = address_line_1<br> self.city = city<br> self.postal_code = postal_code<br> self.email = email<br> self.desired_program = desired_program
<br><br>class Application(object):<br> def __init__(self, candidate):<br> self.candidate = candidate<br><br> def display(self):<br> pass