Popular recipes by Alain Mellan http://code.activestate.com/recipes/users/4065697/2012-01-18T22:15:58-08:00ActiveState Code RecipesSyntactic sugar to create XHTML hierarchies with ElementTree (Python) 2012-01-18T22:15:58-08:00Alain Mellanhttp://code.activestate.com/recipes/users/4065697/http://code.activestate.com/recipes/578020-syntactic-sugar-to-create-xhtml-hierarchies-with-e/ <p style="color: grey"> Python recipe 578020 by <a href="/recipes/users/4065697/">Alain Mellan</a> (<a href="/recipes/tags/xml/">xml</a>). </p> <p>Simplify the code when creating XHTML or XML hierarchies with ElementTree.</p> <p>Usually, I have code like this:</p> <pre class="prettyprint"><code>table = ET.SubElement(body, 'table') table.attrib['border'] = '1' tr = ET.SubElement(table, 'tr') ET.SubElement(tr, 'td').text = 'some text' </code></pre> <p>Using Python's __getattr__ and partial function evaluation allows to create an object that will yield a much simplified syntax.</p> walk a local CVS directory tree (Python) 2008-07-28T17:34:37-07:00Alain Mellanhttp://code.activestate.com/recipes/users/4065697/http://code.activestate.com/recipes/576378-walk-a-local-cvs-directory-tree/ <p style="color: grey"> Python recipe 576378 by <a href="/recipes/users/4065697/">Alain Mellan</a> (<a href="/recipes/tags/cvs/">cvs</a>, <a href="/recipes/tags/files/">files</a>). Revision 2. </p> <p>There are times were I need to generate a manifest, or perform an export of my current CVS sandbox. cvs export works similarly to cvs co, i.e. extracts directly from a repository. I want to generate a clean export, without all the log files, etc, that tend to pollute my work area. I started using os.path.walk and remove what's not in CVS, but in the end the following code was much simpler (especially after taking a look at the source code for os.path.walk :-)</p> sin, cos, tan for Decimal (Python) 2007-07-05T19:49:49-07:00Alain Mellanhttp://code.activestate.com/recipes/users/4065697/http://code.activestate.com/recipes/523018-sin-cos-tan-for-decimal/ <p style="color: grey"> Python recipe 523018 by <a href="/recipes/users/4065697/">Alain Mellan</a> (<a href="/recipes/tags/algorithms/">algorithms</a>, <a href="/recipes/tags/generator/">generator</a>). Revision 2. </p> <p>Implementation of sine, cosine, tangent functions for Decimal arithmetic, using Taylor series expansion. It uses simple numerator and denominator generators.</p> <p>The nice part is, the code is independent from the Decimal library. Feed it a float, it works just the same as if you feed it a Decimal (apart from the precision :-)</p> Unix rename (mv) front-end with GNU Readline (Python) 2007-07-13T20:05:31-07:00Alain Mellanhttp://code.activestate.com/recipes/users/4065697/http://code.activestate.com/recipes/523005-unix-rename-mv-front-end-with-gnu-readline/ <p style="color: grey"> Python recipe 523005 by <a href="/recipes/users/4065697/">Alain Mellan</a> (<a href="/recipes/tags/linux/">linux</a>). Revision 2. </p> <p>Rename (move) a file with help of GNU Readline library.</p>