Hi Everybody,<br><br>&nbsp;&nbsp;&nbsp;&nbsp; I have been working on a parser for myself. I want to create methods on the fly with the information that I get from a file. Here is my question:<br><br>class configure:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;.....stuff deleted......&gt;
<br>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; def parseGlobal(self,projectName,section,project):<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for element in section.childNodes:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if not element.nodeName == &quot;#text&quot;:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.glblFunc
[&quot;get&quot; + project.getAttribute(&quot;name&quot;).encode(&quot;ascii&quot;).capitalize()&nbsp; + element.nodeName.encode(&quot;ascii&quot;).capitalize()] = \<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; lambda self : element.firstChild.data.encode
(&quot;ascii&quot;)<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;...and later on...&gt;<br><br>def addMethod(instName,funcDict):<br>&nbsp;&nbsp;&nbsp; for k,v in funcDict.iteritems():<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; instName.__dict__[k]=new.instancemethod(v,instName,&#39;configure&#39;)
<br><br>The instance name and funcDict (which is the populated self.glblFunc) get sent up to addMethod. This is supposed to create a new method within the instance of my class. Instead, I get a AttributeError exception thrown. So, I check the code using 
inspect.getsource, and for all of the new methods that I create, I get<br><br><br>&#39;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; + element.nodeName.encode(&quot;ascii&quot;).capitalize()] = lambda self :&nbsp; sys.stdout.write(element.firstChild.data.encode
(&quot;ascii&quot;))\n\n&#39;<br><br>instead of <br><br>lambda self :&nbsp; sys.stdout.write(element.firstChild.data.encode(&quot;ascii&quot;)<br><br>Could anybody tell me why this is happening or do you need some more code<br>
<br>Thanks,<br>Tino<br><br><br>