title: How to define a super powerful class-style dict object?
body: <p>Assume that the object meeting my need is called <code>classdic</code>, then the functions of an instance of class <code>classdic</code> are:</p>
  
  <ol>
  <li><p>Query, update, add, and delete data can be all realized in class style way and dict style way (called "two ways").</p></li>
  <li><p>When an attribute or a key not existing, the instance of classdic can automatically build it and make it equal the default value on both instance and dict, thus we can query it both ways (note: not add, just query).</p></li>
  </ol>
  
  <p>So, how can I implement this class?</p>
  
  <p>The example below shows how an instance of this class would work:</p>
  
  <pre><code>dic={'one':1,
  'two':{'four':4,'five':{'six':6,'seven':7}},
  'three':3}
  
  cdic=classdic(dic,default=100)
  
  -------------------query in two ways-------------------------------------------
  &gt;&gt;&gt; cdic.one
  1
  &gt;&gt;&gt; cdic.two
  {'four':4,'five':{'six':6,'seven':7}}
  &gt;&gt;&gt; cdic.two.five.six
  6
  &gt;&gt;&gt; cdic['two']['five']['six']
  6
  -------------------update in two ways-------------------------------------------
  &gt;&gt;&gt; cdic['two']['five']['six']=7
  &gt;&gt;&gt; cdic.two.five.six
  7
  &gt;&gt;&gt; cdic.two.five.six=8
  &gt;&gt;&gt; cdic['two']['five']['six']
  8
  -------------------add in two ways-------------------------------------------
  &gt;&gt;&gt; cdic['two']['five']['eight']=8
  &gt;&gt;&gt; cdic.two.five.eight
  8
  &gt;&gt;&gt; cdic.two.five.nine=9
  &gt;&gt;&gt; cdic['two']['five']['nine']
  9
  -------------------query default in two ways-------------------------------------------
  &gt;&gt;&gt; print cdic['ten']
  100
  &gt;&gt;&gt; cdic.ten
  100
  &gt;&gt;&gt; print cdic.eleven
  100
  &gt;&gt;&gt; cdic['eleven']
  100
  -------------------the final state of cdic-------------------------------------------
  &gt;&gt;&gt; cdic
  {'eleven': 100, 'three': 3, 'two': {'four': 4, 'five': {'nine': 9, 'seven': 7, 'six': 8, 'eight': 8}}, 'ten': 100, 'one': 1}
  </code></pre>