Recursive find and replace of attribute names on a nested Python object
<p>A third party has provided me with a data structure that's a bunch of nested Python objects. It is strictly a tree. Some of the attribute names on these objects are Python reserved words such that attempting to access them results in a SyntaxError:</p>

<pre><code> &gt;&gt;&gt; print mat['model'].rules[8].def.blocklabel
   File "&lt;stdin&gt;", line 1
     print mat['model'].rules[8].def.blocklabel
                              ^
 SyntaxError: invalid syntax
</code></pre>

<p>Here the interpreter complains about the use of "def" as an attribute name. I'd like to recursively search the data structure and change any offending attribute names. What's the easiest way to do it? Tightest recipe wins!</p>

<p>Cheers!</p>
