I&#39;m using IronPython for ASP.Net...have some code (not mine, <a href="http://devhawk.net/2008/05/07/Deserializing+XML+With+IronPython.aspx">http://devhawk.net/2008/05/07/Deserializing+XML+With+IronPython.aspx</a> - Harry Pierson&#39;s) that converts an xml file into an object. It has the below function:<br>
<br>def parse(xml):<br>    xr = XmlReader.Create(xml)<br>    while xr.Read():<br>        xr.MoveToContent()<br>        node = XmlNode(xr)<br>        yield node<br>        if (xr.IsEmptyElement):<br>            node.nodeType = XmlNodeType.EndElement<br>
            del node.attributes<br>            yield node<br><br>This code is problematic as it locks the xml file it is reading. I tried a try...finally to do a .Close() and .Dispose(), but the compiler was not happy with that. Just putting .Close() and .Dispose() at the end doesn&#39;t work.<br>
<br>In reading up, I found this:<br><a href="http://docs.python.org/whatsnew/2.5.html#pep-342">http://docs.python.org/whatsnew/2.5.html#pep-342</a><br><br>&quot;The addition of the close() method has one side effect that isn’t obvious. close() is called when a generator is garbage-collected, so this means the generator’s code gets one last chance to run before the generator is destroyed. This last chance means that try...finally statements in generators can now be guaranteed to work; the finally clause will now always get a chance to run. The syntactic restriction that you couldn’t mix yield statements with a try...finally suite has therefore been removed. &quot;<br>
<br>I&#39;m guessing that this isn&#39;t implemented in the version of IronPython in IP for ASP.Net.<br><br>Does anyone have any ideas on a workaround for the generator for this version?<br><br>Thanks,<br>Adam<br clear="all">
<br>-- <br>Adam Brand<br><br>