I want to be able to create a class (in Python) that once initialized with __init__
, does not accept new attributes, but accepts modifications of existing attributes. There's several hack-ish ways I can see to do this, for example having a __setattr__
method such as
def __setattr__(self, attribute, value):
if not attribute in self.__dict__:
print "Cannot set %s" % attribute
else:
self.__dict__[attribute] = value
and then editing __dict__
directly inside __init__
, but I was wondering if there is a 'proper' way to do this?