Popular recipes tagged "meta:loc=87"http://code.activestate.com/recipes/tags/meta:loc=87/2015-09-29T16:56:16-07:00ActiveState Code RecipesSimple Python Point KD Tree (No scipy/numpy needed) (Python) 2015-09-29T16:56:16-07:00webby1111http://code.activestate.com/recipes/users/4192908/http://code.activestate.com/recipes/579104-simple-python-point-kd-tree-no-scipynumpy-needed/ <p style="color: grey"> Python recipe 579104 by <a href="/recipes/users/4192908/">webby1111</a> (<a href="/recipes/tags/geometry/">geometry</a>, <a href="/recipes/tags/kdtree/">kdtree</a>). </p> <p>A very simple and concise KD-tree for points in python.</p> <p>For labeled points, you may want to check out my other recipe: <a href="https://code.activestate.com/recipes/579103-python-addset-attributes-to-list/?in=user-4192908">Python add/set attributes to list</a></p> Human readable output for bytes and seconds (Python) 2014-07-16T17:21:41-07:00Mike 'Fuzzy' Partinhttp://code.activestate.com/recipes/users/4179778/http://code.activestate.com/recipes/578910-human-readable-output-for-bytes-and-seconds/ <p style="color: grey"> Python recipe 578910 by <a href="/recipes/users/4179778/">Mike 'Fuzzy' Partin</a> (<a href="/recipes/tags/humanize/">humanize</a>). </p> <p>A set of simple functions to represent bytes or seconds in a human readable form.</p> Bash script to create a header for Bash scripts (Bash) 2011-11-02T01:57:07-07:00userendhttp://code.activestate.com/recipes/users/4179007/http://code.activestate.com/recipes/577862-bash-script-to-create-a-header-for-bash-scripts/ <p style="color: grey"> Bash recipe 577862 by <a href="/recipes/users/4179007/">userend</a> (<a href="/recipes/tags/auto/">auto</a>, <a href="/recipes/tags/bash/">bash</a>, <a href="/recipes/tags/create/">create</a>, <a href="/recipes/tags/emacs/">emacs</a>, <a href="/recipes/tags/gpl/">gpl</a>, <a href="/recipes/tags/header/">header</a>, <a href="/recipes/tags/linux/">linux</a>, <a href="/recipes/tags/script/">script</a>, <a href="/recipes/tags/shell/">shell</a>, <a href="/recipes/tags/vim/">vim</a>). Revision 3. </p> <p>This will create a header for a Bash script. It is a nice way keep a track of what your script does and when it was created, the author of the script, etc.. </p> <p>It will open the script automatically with one of the two most popular editor out there, Vim or Emacs! It also checks to see if there is a script with the same name in the current working directory so it will not overwrite another file.</p> <p>v0.4: I had to kick this up a notch. I took the suggestion of "dev h" to add a chance for the user to select another name for the script.</p> <p>Please leave comments and suggestions.</p> Python Immutable Enumerations Using Duck Punching (Python) 2012-10-18T19:41:22-07:00Josh Friendhttp://code.activestate.com/recipes/users/4183977/http://code.activestate.com/recipes/578294-python-immutable-enumerations-using-duck-punching/ <p style="color: grey"> Python recipe 578294 by <a href="/recipes/users/4183977/">Josh Friend</a> (<a href="/recipes/tags/duckpunching/">duckpunching</a>, <a href="/recipes/tags/enum/">enum</a>, <a href="/recipes/tags/enumeration/">enumeration</a>, <a href="/recipes/tags/monkeypatching/">monkeypatching</a>, <a href="/recipes/tags/python/">python</a>). </p> <p>Here's a fun method of creating enumerations in Python using dynamic class creation and duck-punching (monkey-patching). It works by creating a class called <code>enum</code> using the <code>type</code> metaclass. Duck-punching is then used to add properties to the class. the <code>fget</code> method of the property returns the enum value, but the <code>fset</code> and <code>fdel</code> methods throw exceptions, keeping the enumeration immutable. You can have enum values assigned automatically in sequence, assign them yourself, or have a mix of both.</p> Decorators for adding aliases to methods in a class (Python) 2011-04-16T19:29:35-07:00José Nahuel Cuesta Luengohttp://code.activestate.com/recipes/users/4177689/http://code.activestate.com/recipes/577659-decorators-for-adding-aliases-to-methods-in-a-clas/ <p style="color: grey"> Python recipe 577659 by <a href="/recipes/users/4177689/">José Nahuel Cuesta Luengo</a> (<a href="/recipes/tags/alias/">alias</a>, <a href="/recipes/tags/decorator/">decorator</a>). </p> <p>The following recipe can be used as a means to adding aliases to methods in a class.</p> Batting-ball (Python) 2011-07-18T15:11:51-07:00Dominic Innocenthttp://code.activestate.com/recipes/users/4178543/http://code.activestate.com/recipes/577799-batting-ball/ <p style="color: grey"> Python recipe 577799 by <a href="/recipes/users/4178543/">Dominic Innocent</a> (<a href="/recipes/tags/functions/">functions</a>, <a href="/recipes/tags/simple/">simple</a>). </p> <p>Have fun batting a ball about a room &amp; sometimes getting funny results.</p> Simple analogue anim and digital voltmeter with alarm DEMO... (Python) 2011-03-04T19:47:37-08:00Barry Walkerhttp://code.activestate.com/recipes/users/4177147/http://code.activestate.com/recipes/577596-simple-analogue-anim-and-digital-voltmeter-with-al/ <p style="color: grey"> Python recipe 577596 by <a href="/recipes/users/4177147/">Barry Walker</a> (<a href="/recipes/tags/amiga/">amiga</a>, <a href="/recipes/tags/analogue/">analogue</a>, <a href="/recipes/tags/anim/">anim</a>, <a href="/recipes/tags/audio/">audio</a>, <a href="/recipes/tags/demo/">demo</a>, <a href="/recipes/tags/digital/">digital</a>, <a href="/recipes/tags/display/">display</a>, <a href="/recipes/tags/e_uae/">e_uae</a>, <a href="/recipes/tags/linux/">linux</a>, <a href="/recipes/tags/voltmeter/">voltmeter</a>, <a href="/recipes/tags/windows/">windows</a>, <a href="/recipes/tags/winuae/">winuae</a>). </p> <p>I needed a simple standard Python analogue and digital display along with an overload beep when used as a basic voltmeter.</p> <p>Analogue readout, for quick glance. Digital readout, for better accuracy. Beep, to warn me of impending doom... ;o)</p> <p>This was my starter code and works from Python 1.4.x to 2.7.x on MINIMUM platforms, AMIGA A1200, MS Windows ME and Knoppix 5.1.1. It is a stand alone program and the easiest way to start it is to import it as though it is a module.</p> <p>(I DO have a Python 3.x.x version too and WILL be uploaded here in the future.)</p> <p>Although this is a DEMO it did access, (home built), HW from various ports on differing platforms.</p> <p>This module IS needed for it to work:-</p> <p><a href="http://code.activestate.com/recipes/577588-clear-screen-and-beep-for-various-platforms/?in=lang-python" rel="nofollow">http://code.activestate.com/recipes/577588-clear-screen-and-beep-for-various-platforms/?in=lang-python</a></p> <p>These simple HW access modes using standard Python code WILL be released in the future.</p> <p>This DEMO is released as Public Domain and you may modify it as you please...</p> <p>Enjoy finding simple solutions to often very difficult problems...</p> <p>73...</p> <p>Bazza, G0LCU...</p> <p>Team AMIGA...</p> Dijkstra's algorithm for shortest paths (Python) 2010-08-02T13:03:45-07:00poromenoshttp://code.activestate.com/recipes/users/4174550/http://code.activestate.com/recipes/577343-dijkstras-algorithm-for-shortest-paths/ <p style="color: grey"> Python recipe 577343 by <a href="/recipes/users/4174550/">poromenos</a> (<a href="/recipes/tags/algorithms/">algorithms</a>). </p> <p>Dijkstra(G,s) finds all shortest paths from s to each other vertex in the graph, and shortestPath(G,s,t) uses Dijkstra to find the shortest path from s to t. Uses the priorityDictionary data structure (<a href="http://code.activestate.com/recipes/117228/">Recipe 117228</a>) to keep track of estimated distances to each vertex.</p> Simple, if naive, class factory recipe in python (Python) 2009-11-09T07:59:53-08:00Ariel Balterhttp://code.activestate.com/recipes/users/4172249/http://code.activestate.com/recipes/576951-simple-if-naive-class-factory-recipe-in-python/ <p style="color: grey"> Python recipe 576951 by <a href="/recipes/users/4172249/">Ariel Balter</a> (<a href="/recipes/tags/class_factory/">class_factory</a>). Revision 2. </p> <p>I'm a hack programmer -- no formal education. So, I don't know if this is technically a "factory", "abstract factory" or something else.</p> <p>It is a way to generate a class dynamically, perhaps based on run-time data.</p> <p>The point is that you can take a blank class object and dynamically add a constructor, class attributes, and instance methods. In principle, these could be configured dynamically in a program.</p> <p>Since I don't know anything about programming theory, I welcome any criticism/discussion/suggestion. But, please be gentle!</p> @statemethod (Python) 2009-06-15T13:46:39-07:00Charlie Nolanhttp://code.activestate.com/recipes/users/4170745/http://code.activestate.com/recipes/576808-statemethod/ <p style="color: grey"> Python recipe 576808 by <a href="/recipes/users/4170745/">Charlie Nolan</a> (<a href="/recipes/tags/decorator/">decorator</a>, <a href="/recipes/tags/state_pattern/">state_pattern</a>). </p> <p>Decorator for use with objects following the <a href="http://en.wikipedia.org/wiki/State_pattern">state pattern</a>.</p> 分析html格式文件的标记 (Python) 2009-02-21T23:52:05-08:00nillgump nillgumphttp://code.activestate.com/recipes/users/4169273/http://code.activestate.com/recipes/576658-html/ <p style="color: grey"> Python recipe 576658 by <a href="/recipes/users/4169273/">nillgump nillgump</a> (<a href="/recipes/tags/html/">html</a>). </p> <p>分析html格式文件的标记</p> Create SQL tables from CSV files (Python) 2010-02-24T13:47:36-08:00Matt Keranenhttp://code.activestate.com/recipes/users/38288/http://code.activestate.com/recipes/498130-create-sql-tables-from-csv-files/ <p style="color: grey"> Python recipe 498130 by <a href="/recipes/users/38288/">Matt Keranen</a> (<a href="/recipes/tags/database/">database</a>). </p> <p>Script generates CREATE TABLE statements based on the width of data present in comma delimited (csv) test files. Setting the correct datatypes (other than VARCHAR), is still a manual adventure.</p> <h5>TODOs:</h5> <ul> <li>Eliminate '#N/A', '@NA' from data</li> <li>Remove commas from numeric data</li> <li>Check for duplicate column names</li> <li>Create BCP format file or INSERT statements?</li> </ul> Read simple initialization file (Python) 2006-09-22T10:20:30-07:00Rick Pricehttp://code.activestate.com/recipes/users/779506/http://code.activestate.com/recipes/498125-read-simple-initialization-file/ <p style="color: grey"> Python recipe 498125 by <a href="/recipes/users/779506/">Rick Price</a> . </p> <p>This recipe can be used to read in simple human readable intialization files. It uses callback methods similar to some SAX implementations I have seen.</p> Covert Microsoft Office InfoPath 2003 files to CSV report (Python) 2005-11-02T13:18:49-08:00Anthony Barkerhttp://code.activestate.com/recipes/users/122940/http://code.activestate.com/recipes/442520-covert-microsoft-office-infopath-2003-files-to-csv/ <p style="color: grey"> Python recipe 442520 by <a href="/recipes/users/122940/">Anthony Barker</a> . </p> <p>I needed a quick hack to extract some data from MS InfoPath files stored on a file server. Infopath data files are stored as XML so it was fairly straight forward to extract the required information. The outputed file is report.csv and a log file is called reportlog.txt. It reads settings from config.ini.</p> MarkupString (Python) 2005-02-23T19:17:32-08:00Thomas Hinklehttp://code.activestate.com/recipes/users/2330830/http://code.activestate.com/recipes/389023-markupstring/ <p style="color: grey"> Python recipe 389023 by <a href="/recipes/users/2330830/">Thomas Hinkle</a> (<a href="/recipes/tags/xml/">xml</a>). Revision 2. </p> <p>A subclass of String that allows simple handling of pango markup or other simple XML markup. The goal here is to allow a slice of a python markup string to "do the right thing" and preserve formatting correctly. In other word, MarkupString(&lt;i&gt;Hello World&lt;/i&gt;)[6:] = "&lt;i&gt;World&lt;/i&gt;"</p> Dijkstra's algorithm for shortest paths (Python) 2002-04-04T12:38:22-08:00David Eppsteinhttp://code.activestate.com/recipes/users/218935/http://code.activestate.com/recipes/119466-dijkstras-algorithm-for-shortest-paths/ <p style="color: grey"> Python recipe 119466 by <a href="/recipes/users/218935/">David Eppstein</a> (<a href="/recipes/tags/algorithms/">algorithms</a>). </p> <p>Dijkstra(G,s) finds all shortest paths from s to each other vertex in the graph, and shortestPath(G,s,t) uses Dijkstra to find the shortest path from s to t. Uses the priorityDictionary data structure (<a href="http://code.activestate.com/recipes/117228/">Recipe 117228</a>) to keep track of estimated distances to each vertex.</p> Splitting iterators (Python) 2003-07-29T18:14:41-07:00Heiko Wundramhttp://code.activestate.com/recipes/users/1291227/http://code.activestate.com/recipes/213027-splitting-iterators/ <p style="color: grey"> Python recipe 213027 by <a href="/recipes/users/1291227/">Heiko Wundram</a> (<a href="/recipes/tags/algorithms/">algorithms</a>). </p> <p>Implementation of isplit, a function that splits iterators into two equal ones, which return similar values, but are exact copies of one another.</p>