Popular recipes tagged "meta:loc=153"http://code.activestate.com/recipes/tags/meta:loc=153/2013-12-14T00:28:36-08:00ActiveState Code RecipesPretty and Stated HTMLParsers (Python) 2013-12-14T00:28:36-08:00Ádám Szieberthhttp://code.activestate.com/recipes/users/4188745/http://code.activestate.com/recipes/578787-pretty-and-stated-htmlparsers/ <p style="color: grey"> Python recipe 578787 by <a href="/recipes/users/4188745/">Ádám Szieberth</a> (<a href="/recipes/tags/html/">html</a>, <a href="/recipes/tags/htmlparser/">htmlparser</a>, <a href="/recipes/tags/state/">state</a>). Revision 2. </p> <p>Extensions of html.parser.HTMLParser().</p> <p>PrettyHTMLParser() does not splits data into chuncks by HTML entities. StatedHTMLParser() can have many state-dependent handlers which helps parsing HTML pages alot.</p> Draw SVG Images In Python (Python recipe) - enhanced Version (Python) 2012-05-10T16:27:18-07:00Isendrak Skatasmidhttp://code.activestate.com/recipes/users/4182031/http://code.activestate.com/recipes/578123-draw-svg-images-in-python-python-recipe-enhanced-v/ <p style="color: grey"> Python recipe 578123 by <a href="/recipes/users/4182031/">Isendrak Skatasmid</a> (<a href="/recipes/tags/graphics/">graphics</a>). </p> <p>This script draws simple SVG images composed of circles, squares, lines, text, etc.</p> Python Tkinter Canvas Rectangle Selection Box (Python) 2010-10-01T02:17:50-07:00Sunjay Varmahttp://code.activestate.com/recipes/users/4174115/http://code.activestate.com/recipes/577409-python-tkinter-canvas-rectangle-selection-box/ <p style="color: grey"> Python recipe 577409 by <a href="/recipes/users/4174115/">Sunjay Varma</a> (<a href="/recipes/tags/canvas/">canvas</a>, <a href="/recipes/tags/rectangle/">rectangle</a>, <a href="/recipes/tags/selection/">selection</a>, <a href="/recipes/tags/tkinter/">tkinter</a>). </p> <p>A simple, yet effective rectangle selection box. :)</p> <p>Works with a tkinter canvas! Just add the class and set it up like in the example code. The cross heir was my own touch, the RectTracker only draws a box.</p> <p>Have fun! And please don't just vote down, post what you don't like if you don't like it.</p> File Uniter (C++) 2010-12-01T03:10:13-08:00FB36http://code.activestate.com/recipes/users/4172570/http://code.activestate.com/recipes/577481-file-uniter/ <p style="color: grey"> C++ recipe 577481 by <a href="/recipes/users/4172570/">FB36</a> (<a href="/recipes/tags/data_compression/">data_compression</a>). </p> <p>Unites N files into a single file (or separates them back).</p> <p>This utility can be used together w/ my other post titled "Huffman Data Compression" to enable compression of multiple files.</p> Pi_Approximation (Python) 2011-01-27T12:50:56-08:00Fouad Teniouhttp://code.activestate.com/recipes/users/4155345/http://code.activestate.com/recipes/577067-pi_approximation/ <p style="color: grey"> Python recipe 577067 by <a href="/recipes/users/4155345/">Fouad Teniou</a> (<a href="/recipes/tags/mathematics/">mathematics</a>). Revision 3. </p> <p>Pi is a constant, an irrational number and its notation represent the sixteenth letter of the Greek alphabet, though its value is equal to the ratio of a circle’s circumference to its diameter.</p> <p>However, <strong>a Muslim scientist Abu-Abdullah Muhammad Ibn Musa al-Khwarizmi</strong> the founder of algebra ( derived from the Arabic word El-Jabr ), arithmetic, and trigonometry, an astronomer, and a geographer C850 studied and proved Pi’s irrationality.(<strong>algorithm is derived from his name Khwarizmi</strong> ).</p> <p>I used the circle equation x²+y² = 1 of radius 1 centred at (0,0) and the circle area’s formula to approximate Pi value. y²= 1-x² and y = √(1-x²) is the upper semicircle which will extend from x = -1 to x = 1 and the rectangle method is used to approximate this area of an interval [-1,1]. </p> <p>The area of a circle is A = πr², thus the semicircle of radius 1 will have an area A = ½ π(1²).</p> <p>Using my Pi_Approximation program allows you to represent Pi to infinity of digits, and this will depend of the project type and the precision needed, though space programs require to approximate pi at its maximum precision. </p> <p>And my Pi_Approximation program allows you to make a better Pi’s approximation than the scientific Calculators </p> Update stock quote using Yahoo! Finance web services (Python) 2008-06-22T18:33:50-07:00Wai Yip Tunghttp://code.activestate.com/recipes/users/2382677/http://code.activestate.com/recipes/573471-update-stock-quote-using-yahoo-finance-web-service/ <p style="color: grey"> Python recipe 573471 by <a href="/recipes/users/2382677/">Wai Yip Tung</a> (<a href="/recipes/tags/excel/">excel</a>, <a href="/recipes/tags/math/">math</a>). Revision 2. </p> <p>This script update the stock quote on your spreadsheet by fetching the latest quote from Yahoo!Finance web services. It uses the pywin32 library to update the cells on an Excel spreadsheet.</p> Easy Cross Platform Excel Parsing With Xlrd (Python) 2006-04-07T22:45:51-07:00Bryan Niederbergerhttp://code.activestate.com/recipes/users/2843232/http://code.activestate.com/recipes/483742-easy-cross-platform-excel-parsing-with-xlrd/ <p style="color: grey"> Python recipe 483742 by <a href="/recipes/users/2843232/">Bryan Niederberger</a> (<a href="/recipes/tags/ui/">ui</a>). Revision 3. </p> <p>Easily extract data from microsoft excel files using this wrapper class for xlrd (<a href="http://www.lexicon.net/sjmachin/xlrd.htm" rel="nofollow">http://www.lexicon.net/sjmachin/xlrd.htm</a>). The class allows you to create a generator which returns excel data one row at a time as either a list or dictionary. I found this very handy for easily pulling in a variety of excel files without having to deal with COM calls or even needing to have windows.</p> Running Batch Commands (Python) 2006-07-19T07:38:20-07:00Jordan Callicoathttp://code.activestate.com/recipes/users/2948075/http://code.activestate.com/recipes/496897-running-batch-commands/ <p style="color: grey"> Python recipe 496897 by <a href="/recipes/users/2948075/">Jordan Callicoat</a> . Revision 4. </p> <p>This recipe is a simple (very simple) batch process dispatcher. It allows you to utilize a simple file with a list of commands to run to make your command-line life a little easier. I use it for mencoder so I don't have to type/paste in a bunch of commands for backing up my DVDs. I can just write a batch file. And if there is an error somewhere along the way, or I need to stop for some reason, I can just start where I left off when I am ready.</p> Caching and throttling for urllib2 (Python) 2006-04-14T15:59:41-07:00Staffan Malmgrenhttp://code.activestate.com/recipes/users/1149346/http://code.activestate.com/recipes/491261-caching-and-throttling-for-urllib2/ <p style="color: grey"> Python recipe 491261 by <a href="/recipes/users/1149346/">Staffan Malmgren</a> (<a href="/recipes/tags/web/">web</a>). </p> <p>This code implements a cache (CacheHandler) and a throttling mechanism (ThrottlingProcessor) for urllib2. By using them, you can ensure that subsequent GET requests for the same URL returns a cached copy instead of causing a roundtrip to the remote server, and/or that subsequent requests to a server are paused for a couple of seconds to avoid overloading it. The test code at the end explains all there is to it.</p> sorting -- old to new python 2.4 style (heapq,bisect,list.sort keywords,itemgetter) (Python) 2006-09-13T12:28:57-07:00John Nielsenhttp://code.activestate.com/recipes/users/135654/http://code.activestate.com/recipes/305304-sorting-old-to-new-python-24-style-heapqbisectlist/ <p style="color: grey"> Python recipe 305304 by <a href="/recipes/users/135654/">John Nielsen</a> (<a href="/recipes/tags/algorithms/">algorithms</a>). Revision 2. </p> <p>Python 2.4 has added a new feature to handle the problem where you needed to do a sort based off of part of the data. In effect, it has simplified the Schwartzian Transform (which I learned many years ago from an perl article written by Randall Schwartz). The following code will start with the older style python sorting approaches, and then show the bisect and heapq modules, and finally the key,cmp,reverse methods newly added to sort. The sort method of the list is an in-place sort. There is also a new sorted() function which returns a copy of the list sorted for you.</p>