This is what I'm talking about:
For example:
class User():
def __init__(self, username, fullname):
self.username = username
self.fullname = fullname
def update(self, arg, value):
if arg is 'username':
self.username = value
elif arg is 'fullname':
self.fullname = value
In the update function I am letting the user input a param they want to update, arg
, with the value specified, value
.
If I ever wanted to add more args to the User
class, I would need to change the update function as well with the added arguments. How can I create a dynamic update function that accepts any of the existing arguments in the class __init__
?
Ex: If I added email
arg to __init__()
, I would need to add this to the update()
function:
if arg is 'email':
self.email = value
^ this would get annoying after a while.
I hope you understand what I'm asking. If you need any more clarification let me know