Why does Kenneth pass in the *args and **kwargs if we don't need them?
What's the point of passing in the *args and **kwargs if we don't need them or even as he said he couldn't think of a reason to use them?
Ari Misha19,227 Points
Hiya Michael! You can always use "setattr" method and assign 'em values. Here is the code for using setattr on your kwargs:
for keys, values in kwargs.items(): setattr(self, keys, value)
Put this code in your init method in order to initialize the object with any no. of arguments. Also remember the zen of Python or guidelines for writing Python codes better , "explicit is better than implicit". So yeah being explicit is considered the best practice in Python.
I hope it helped. (:
I think he uses *args and **kwargs even in the case we're not using them because, otherwise, if the user of the code passes any not needed argument it would cause an TypeError saying that he exceeded the number of arguments of the class.
But we solve this problem using args and kwargs as parameters because the code runs without error for whatever number of arguments passed to the class, since they will all be caught by *args and **kwargs. Since we won't use them, we don't pass these arguments further.
That is my interpretation of this. I'm not entirely sure if I'm right though.
Hope it helped you!