Constructors in Python often look like this:
class SomeClass:
def __init__(self, a, b = None, c = defC):
self.a = a
self.b = b or []
self.c = c
Is there a shortcut for this, e.g. to simply define __init__(self,**kwargs) and use the keys as properties of self?
One problem with
is that it includes
self, so you getself.self. It would be better to filterselfout oflocals()eg.
You can defend against accidentally overwriting methods with this variation
If you don’t want it to fail silently, you could also check beforehand like this