KeyError: '_OrderedDict__root?
<p>Hi I have following code snippet which gives KeyError. I have checked other links specifying <code>make __init__ call to Ordered Dict</code> which I have done. But still no luck.</p>

<pre><code>from collections import OrderedDict

class BaseExcelNode(OrderedDict):
    def __init__(self):
        super(BaseExcelNode, self).__init__()
        self.start_row = -1
        self.end_row = -1
        self.col_no = -1

    def __getattr__(self, name):
        return self[name]

    def __setattr__(self, name, value):
        self[name] = value
BaseExcelNode()
</code></pre>

<p><code>Error</code>:</p>

<pre><code>Traceback (most recent call last):
  File "CIMParser.py", line 29, in &lt;module&gt;
    BaseExcelNode()
  File "CIMParser.py", line 9, in __init__
    super(BaseExcelNode, self).__init__()
  File "C:\Python27\lib\collections.py", line 64, in __init__
    self.__root
  File "CIMParser.py", line 15, in __getattr__
    return self[name]
KeyError: '_OrderedDict__root'
</code></pre>

<p>Using monkey patching method:</p>

<pre><code>from collections import OrderedDict

class BaseExcelNode(OrderedDict):
    def __init__(self):
        super(BaseExcelNode, self).__init__()
        self.start_row = -1
        self.end_row = -1
        self.col_no = -1

    def __getattr__(self, name):
        if not name.startswith('_'):
            return self[name]
        super(BaseExcelNode, self).__getattr__(name)

    def __setattr__(self, name, value):
        if not name.startswith('_'):
            self[name] = value
        else:
            super(BaseExcelNode, self).__setattr__(name, value)

b = BaseExcelNode()
</code></pre>

python ordereddictionary