Popular recipes by Mike Hostetler http://code.activestate.com/recipes/users/138739/2006-12-04T21:52:58-08:00ActiveState Code RecipesKeyed Dictionary -- strict key values in a dictionary (Python) 2006-12-04T21:52:58-08:00Mike Hostetlerhttp://code.activestate.com/recipes/users/138739/http://code.activestate.com/recipes/499296-keyed-dictionary-strict-key-values-in-a-dictionary/ <p style="color: grey"> Python recipe 499296 by <a href="/recipes/users/138739/">Mike Hostetler</a> (<a href="/recipes/tags/extending/">extending</a>). Revision 2. </p> <p>The KeyedDict object keeps a list of approved key values. If you try to assigned an unapproved key to a value, an exception is thrown.</p> <p>When you create the object, you give it a sequence (tuple, list, etc.) of key objects and then, when you set an item with a key, it will make sure that the key is in the "approved" list. If you try to set an item with a key that isn't in your approved list, you get an TypeError exception.</p> Lowering the first word in a CamelCase Word (Python) 2005-02-16T13:13:45-08:00Mike Hostetlerhttp://code.activestate.com/recipes/users/138739/http://code.activestate.com/recipes/387663-lowering-the-first-word-in-a-camelcase-word/ <p style="color: grey"> Python recipe 387663 by <a href="/recipes/users/138739/">Mike Hostetler</a> (<a href="/recipes/tags/text/">text</a>). </p> <p>This function converts the first word in a CamelCase work to lowercase. I.e. "CustomerID" becomes "customerID", "XMLInfo" becomes "xmlInfo"</p> Breaking large XML documents into chunks to speed processing (Python) 2001-10-31T12:56:39-08:00Mike Hostetlerhttp://code.activestate.com/recipes/users/138739/http://code.activestate.com/recipes/84515-breaking-large-xml-documents-into-chunks-to-speed-/ <p style="color: grey"> Python recipe 84515 by <a href="/recipes/users/138739/">Mike Hostetler</a> (<a href="/recipes/tags/xml/">xml</a>). </p> <p>One of the few problems with using Python to process XML is the speed -- if the XML becomes somewhat large (&gt;1Mb), it slows down exponentially as the size of the XML increases. One way to increase the processing speed is to break the XML down via tag name. This is especially handy if you are only interested in one part of the XML, or between certain elements throughout the XML.</p> <p>Here is a function that I came up with to handle this problem -- I call it "tinyDom". It uses the Sax reader from PyXML, although it could be easily changed for minidom, etc.</p> <p>The In parameters are the XML as a string, the tag name that you want to build the DOM around, and an optional postition to start at within the XML. It returns a DOM tree and the character position that it stopped at.</p>