Popular recipes by runsun pan http://code.activestate.com/recipes/users/2638612/2009-05-06T11:59:16-07:00ActiveState Code RecipesEasy Property Creation in Python (Python) 2009-05-06T11:59:16-07:00runsun panhttp://code.activestate.com/recipes/users/2638612/http://code.activestate.com/recipes/576742-easy-property-creation-in-python/ <p style="color: grey"> Python recipe 576742 by <a href="/recipes/users/2638612/">runsun pan</a> (<a href="/recipes/tags/class/">class</a>, <a href="/recipes/tags/property/">property</a>, <a href="/recipes/tags/property_creation/">property_creation</a>). Revision 4. </p> <p>Presented in this recipe is a function <strong>prop</strong>, with that a property <em>myprop</em> can be created as simple as:</p> <pre class="prettyprint"><code>@prop def myprop(): pass </code></pre> <p>It has only 7 lines of code, easy to understand, easy to customize, will make the code look much netter and will save you a lot of typing.</p> <p>See discussion and the doc test string for more complicated usages.</p> <p>Note: This is a recipe created with python v.2.5.2.</p> Dictionary tool for lazy typers (Python) 2006-08-01T13:10:36-07:00runsun panhttp://code.activestate.com/recipes/users/2638612/http://code.activestate.com/recipes/496926-dictionary-tool-for-lazy-typers/ <p style="color: grey"> Python recipe 496926 by <a href="/recipes/users/2638612/">runsun pan</a> (<a href="/recipes/tags/extending/">extending</a>). </p> <p>This recipe provides an alternative way of generating and updating dictionaries. It savs couple of keystrokes, making routine dict operations easier.</p> BaseDict -- a dict that (1) accesses data thru attributing (2) copy correctly (Python) 2006-01-27T06:44:54-08:00runsun panhttp://code.activestate.com/recipes/users/2638612/http://code.activestate.com/recipes/473790-basedict-a-dict-that-1-accesses-data-thru-attribut/ <p style="color: grey"> Python recipe 473790 by <a href="/recipes/users/2638612/">runsun pan</a> (<a href="/recipes/tags/shortcuts/">shortcuts</a>). Revision 3. </p> <p>&lt;code&gt;A dict extension that has the following features:</p> <pre class="prettyprint"><code>1. dual data storages: use 'bd.x' or 'bd["x"]' for one, and bd.getDict() for another. 2. All the followings are equivalent:: bd['x']= val bd.x = val bd.setItem('x', val) # Return bd 3. bd.setDict('x',val) will save 'x' to bd.__dict__, but not bd.items 4. When copy, copy the internal object correctly. </code></pre> <p>&lt;/code&gt;</p> Importer-specific module initialization (Python) 2006-02-03T15:06:53-08:00runsun panhttp://code.activestate.com/recipes/users/2638612/http://code.activestate.com/recipes/473823-importer-specific-module-initialization/ <p style="color: grey"> Python recipe 473823 by <a href="/recipes/users/2638612/">runsun pan</a> (<a href="/recipes/tags/sysadmin/">sysadmin</a>). </p> <p>Sometimes we want to have a module initialized in different ways. This function, getimporter(), while placed inside a module X, allow you to initialize module X according to the module (properties) that is importing X.</p> groupbyhead: Group a list of items according to the starting character(s) of items. (Python) 2006-01-03T09:26:05-08:00runsun panhttp://code.activestate.com/recipes/users/2638612/http://code.activestate.com/recipes/465830-groupbyhead-group-a-list-of-items-according-to-the/ <p style="color: grey"> Python recipe 465830 by <a href="/recipes/users/2638612/">runsun pan</a> (<a href="/recipes/tags/algorithms/">algorithms</a>). </p> <p>Group a list of items according to the starting character(s) of items. This is based on Raymond Hettinger's groupby class: <a href="http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/259173" rel="nofollow">http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/259173</a></p>