In Python, say I have some class, Circle, that inherits from Shape. Shape needs x- and y-coordinates, and, in addition, Circle needs a radius. I want to be able to initializ
If you wish to assign automatically, I suggest the following approach:
def __init__(self, **kwargs): for key, value in kwargs.iteritems(): setattr(self, key, value)
which, in terms of style, is somewhere in between writing it explicitly and hacking it yourself using self.__dict__.
self.__dict__