title: Advantages of UserDict class?
body: <p>What are advantages of using <strong><code>UserDict</code></strong> class?</p>
  <p>I mean, what I really get if instead of</p>
  <pre><code>class MyClass(object):
      def __init__(self):
          self.a = 0
          self.b = 0
  ...
  m = MyClass()
  m.a = 5
  m.b = 7
  </code></pre>
  <p>I will write the following:</p>
  <pre><code>class MyClass(UserDict):
      def __init__(self):
          UserDict.__init__(self)
          self[&quot;a&quot;] = 0
          self[&quot;b&quot;] = 0
  ...
  m = MyClass()
  m[&quot;a&quot;] = 5
  m[&quot;b&quot;] = 7
  </code></pre>
  <p><strong>Edit</strong>: If I understand right I can add new fields to an object in a runtime in both cases?</p>
  <pre><code>m.c = &quot;Cool&quot;
  </code></pre>
  <p>and</p>
  <pre><code>m[&quot;c&quot;] = &quot;Cool&quot;
  </code></pre>