Hi Everybody,<br><br> 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> <.....stuff deleted......>
<br> def parseGlobal(self,projectName,section,project):<br> for element in section.childNodes:<br> if not element.nodeName == "#text":<br> self.glblFunc
["get" + project.getAttribute("name").encode("ascii").capitalize() + element.nodeName.encode("ascii").capitalize()] = \<br> lambda self : element.firstChild.data.encode
("ascii")<br><br> <...and later on...><br><br>def addMethod(instName,funcDict):<br> for k,v in funcDict.iteritems():<br> instName.__dict__[k]=new.instancemethod(v,instName,'configure')
<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>' + element.nodeName.encode("ascii").capitalize()] = lambda self : sys.stdout.write(element.firstChild.data.encode
("ascii"))\n\n'<br><br>instead of <br><br>lambda self : sys.stdout.write(element.firstChild.data.encode("ascii")<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>