title: Prevent creating new attributes outside __init__
body: <p>I want to be able to create a class (in Python) that once initialized with <code>__init__</code>, 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 <code>__setattr__</code> method such as</p>
  
  <pre><code>def __setattr__(self, attribute, value):
      if not attribute in self.__dict__:
          print "Cannot set %s" % attribute
      else:
          self.__dict__[attribute] = value
  </code></pre>
  
  <p>and then editing <code>__dict__</code> directly inside <code>__init__</code>, but I was wondering if there is a 'proper' way to do this?</p>