Python interaction between __setattr__ and self.__dict__
<p>If I make a class instance like this</p>

<pre><code>class MyClass(object):
    pass
x = MyClass()
</code></pre>

<p>I can then set attributes on x as follows:</p>

<p><code>x.myAttr = 1</code> or <code>x.__setattr__('myAttr', 1)</code></p>

<p>However, if I make a dict</p>

<pre><code>d = {}
</code></pre>

<p>I cannot set attributes on it. For example, if I do this</p>

<pre><code>d.__setattr__('myAttr', 1)
</code></pre>

<p>I get the error " 'dict' object has no attribute 'myAttr' " The same thing happens if I try</p>

<pre><code>d.myAttr = 1
</code></pre>

<p>I have noticed that in the case of x.myAttr = 1 what actually happens is that</p>

<pre><code>x.__dict__
</code></pre>

<p>gets updated with a new key, so it must be that</p>

<pre><code>d.__setattr__
</code></pre>

<p>doesn't work because d doesn't have</p>

<pre><code>d.__dict__
</code></pre>

<p>simply because d <em>is</em> a dict. I would appreciate it very much if someone could thoroughly explain what's going on here.</p>

<p>Do all python objects have <code>.__dict__</code>?</p>

<p>Why does my attempt at calling <code>d.__setattr__</code> result in an error saying that the attribute doesn't exist?</p>

<p>Is there a specific heirarchy of built-in types that I should know about? A simple reference would be much appreciated.</p>

<p>python 2.6.4</p>

<p>Windows XP Pro x64 SP2</p>
