[EMAIL PROTECTED] wrote: > Is it possible to run data that's from an xml file as python code, by > this I mean the following. > > In a xml file there's the following data > > <code><![CDATA[self.wTree.signal_autoconnect(dic)]]></code> > > Now I want to extract the self.wTree.signal_autoconnect(dic)* from the > xml file and make it possible that Python runs this, instead of having > a python file were with the hardcoded self.wTre.. in it.
from elementtree import ElementTree as ET text = """<doc><code><![CDATA[object.method('hello')]]></code></doc>""" doc = ET.fromstring(text) class Object: def method(self, value): print value # populate the namespace namespace = { "object": Object() } # execute all code fragments for code_elem in doc.findall(".//code"): exec code_elem.text in namespace </F> -- http://mail.python.org/mailman/listinfo/python-list