Popular Python recipes tagged "meta:requires=pprint"http://code.activestate.com/recipes/langs/python/tags/meta:requires=pprint/2012-05-23T15:33:13-07:00ActiveState Code RecipesA small python script to detect .net framwork versions installed on your local windows machine (Python) 2012-05-23T15:33:13-07:00Yong Zhaohttp://code.activestate.com/recipes/users/4182173/http://code.activestate.com/recipes/578143-a-small-python-script-to-detect-net-framwork-versi/ <p style="color: grey"> Python recipe 578143 by <a href="/recipes/users/4182173/">Yong Zhao</a> (<a href="/recipes/tags/dotnet/">dotnet</a>, <a href="/recipes/tags/framework/">framework</a>, <a href="/recipes/tags/python_scripts/">python_scripts</a>, <a href="/recipes/tags/windows_registry/">windows_registry</a>, <a href="/recipes/tags/_winreg/">_winreg</a>). </p> <p>This small script uses the _winreg module to find out the .net framwork versions installed on your local machine. tested using IronPython 2.7.1.</p> Dynamically Generated Python State Machine (Python) 2011-09-30T05:16:56-07:00__nerohttp://code.activestate.com/recipes/users/4177968/http://code.activestate.com/recipes/577693-dynamically-generated-python-state-machine/ <p style="color: grey"> Python recipe 577693 by <a href="/recipes/users/4177968/">__nero</a> (<a href="/recipes/tags/dynamically/">dynamically</a>, <a href="/recipes/tags/finite/">finite</a>, <a href="/recipes/tags/generated/">generated</a>, <a href="/recipes/tags/machine/">machine</a>, <a href="/recipes/tags/state/">state</a>). Revision 6. </p> <p>This is a state machine template. It can be used as a state machine, or a state machine tester. There is very little setup required and all the states are added based on the state docstring. I made this after a friend came to me asking how I'd implement one, complaining that he couldn't find a nice example. I hope this helps.</p> Dot-style nested lookups over dictionary based data structures (Python) 2008-12-14T14:32:59-08:00David Mosshttp://code.activestate.com/recipes/users/4124829/http://code.activestate.com/recipes/576586-dot-style-nested-lookups-over-dictionary-based-dat/ <p style="color: grey"> Python recipe 576586 by <a href="/recipes/users/4124829/">David Moss</a> (<a href="/recipes/tags/access/">access</a>, <a href="/recipes/tags/attribute/">attribute</a>, <a href="/recipes/tags/dictionaries/">dictionaries</a>). Revision 2. </p> <p>This recipe allows you to present dictionary based nested data stuctures in your Python code as objects with nested attributes.</p> <p>It provides dot ('.') based attribute lookups, like this :-</p> <pre class="prettyprint"><code>&gt;&gt;&gt; x = d.foo.bar.baz </code></pre> <p>instead of the usual (and longer) Python dictionary syntax lookups :-</p> <pre class="prettyprint"><code>&gt;&gt;&gt; x = d['foo']['bar']['baz'] </code></pre> <p>This recipe saves you <em>lot</em> of typing!</p> <p>For simplicity and readability this particular version show a read only lookup class.</p> Rename MP3 files from ID3 tags (does not require external ID3 modules) (Python) 2011-11-05T15:27:32-07:00ccpizzahttp://code.activestate.com/recipes/users/4170754/http://code.activestate.com/recipes/576811-rename-mp3-files-from-id3-tags-does-not-require-ex/ <p style="color: grey"> Python recipe 576811 by <a href="/recipes/users/4170754/">ccpizza</a> (<a href="/recipes/tags/id3/">id3</a>, <a href="/recipes/tags/mp3/">mp3</a>, <a href="/recipes/tags/rename/">rename</a>). Revision 5. </p> <p>Rename MP3 files in the current folder according to ID3 tags. This is based on Ned Batchelder's id3reader class. I only added the code in the <code>__main__</code> method.</p> <ul> <li>When run without arguments, the script renames the files in the current folder. The directory can be specified explicitly as the first argument.</li> <li>The files do not need to necessarily have the <code>MP3</code> extension.</li> <li>To move the files to directories based on album name use the <code>-d</code> switch.</li> <li>Does not work with other file types, such as OGG, M4A, MP4, etc.</li> <li>This is a quick and dirty script that works for me most of the times. If you need more power, try mutagen, picard, mp3tag or something similar.</li> </ul> Introspect RPM module in Python so we can work out how to use the headers (Python) 2009-05-20T15:25:06-07:00Jonathan Cervidaehttp://code.activestate.com/recipes/users/4170395/http://code.activestate.com/recipes/576767-introspect-rpm-module-in-python-so-we-can-work-out/ <p style="color: grey"> Python recipe 576767 by <a href="/recipes/users/4170395/">Jonathan Cervidae</a> (<a href="/recipes/tags/rpm/">rpm</a>). Revision 2. </p> <p>It will show you all the attributes of the first package you have installed and their named keys in the RPM module.</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> mad debugging using __builtin__ (Python) 2008-07-28T09:40:16-07:00Robin Beckerhttp://code.activestate.com/recipes/users/880795/http://code.activestate.com/recipes/576381-mad-debugging-using-__builtin__/ <p style="color: grey"> Python recipe 576381 by <a href="/recipes/users/880795/">Robin Becker</a> . </p> <p>Nasty way to get your debugging functions available everywhere.</p> Simple maps and lists from XML (Python) 2007-04-14T13:47:45-07:00Adam Hupphttp://code.activestate.com/recipes/users/117023/http://code.activestate.com/recipes/511472-simple-maps-and-lists-from-xml/ <p style="color: grey"> Python recipe 511472 by <a href="/recipes/users/117023/">Adam Hupp</a> (<a href="/recipes/tags/xml/">xml</a>). </p> <p>There are a several ways to represent collections of key/value pairs in XML, which makes it more difficult than necessary to use that data in python. By taking advantage of common patterns in the XML it is easy to turn most formats into collections of lists and dicts.</p> Persistent Dictionary with Text Backend (Python) 2007-03-13T22:11:20-07:00Christoph Devenogeshttp://code.activestate.com/recipes/users/4040281/http://code.activestate.com/recipes/502289-persistent-dictionary-with-text-backend/ <p style="color: grey"> Python recipe 502289 by <a href="/recipes/users/4040281/">Christoph Devenoges</a> (<a href="/recipes/tags/database/">database</a>). Revision 3. </p> <p>A crude persistent dict class. Intended for saving GUI user preferences that can be hand edited, cf. shelve module. Probably not suitable for large amounts of data.</p> Yielding out of nested routines by metaclass transformation (Python) 2006-11-17T04:16:35-08:00Bernhard Mulderhttp://code.activestate.com/recipes/users/189076/http://code.activestate.com/recipes/498270-yielding-out-of-nested-routines-by-metaclass-trans/ <p style="color: grey"> Python recipe 498270 by <a href="/recipes/users/189076/">Bernhard Mulder</a> (<a href="/recipes/tags/threads/">threads</a>). Revision 2. </p> <p>Python 2.5 improved the support for generators, making it easier to use coroutines. If you want to use coroutines, however, you can not transfer control out of nested functions. You can eliminate this restriction by systematically converting regular functions into generator functions as demonstrated by this recipe <a href="http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/474127" rel="nofollow">http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/474127</a> The script below might serve as a starting point to do this transformation automatically, making the use of coroutines (tasklets, lightweight threads...) more natural.</p> Iterate over .MP4 atoms (Python) 2006-08-23T14:56:34-07:00Christos Georgiouhttp://code.activestate.com/recipes/users/418040/http://code.activestate.com/recipes/496984-iterate-over-mp4-atoms/ <p style="color: grey"> Python recipe 496984 by <a href="/recipes/users/418040/">Christos Georgiou</a> (<a href="/recipes/tags/files/">files</a>). </p> <p>This recipe yields the atoms contained in an MP4 file. Mostly used for extracting the tags contained in it (artist, title etc) using a convenience class (M4ATags). Implemented as an generator.</p> Table splitter (Python) 2006-09-13T17:13:18-07:00bearophile -http://code.activestate.com/recipes/users/2403049/http://code.activestate.com/recipes/498093-table-splitter/ <p style="color: grey"> Python recipe 498093 by <a href="/recipes/users/2403049/">bearophile -</a> (<a href="/recipes/tags/text/">text</a>). </p> <p>To split a textual table automatically. Improved from a comp.lang.python request.</p> profiling threads (Python) 2006-01-08T14:01:16-08:00Maciej Obarskihttp://code.activestate.com/recipes/users/2559120/http://code.activestate.com/recipes/465831-profiling-threads/ <p style="color: grey"> Python recipe 465831 by <a href="/recipes/users/2559120/">Maciej Obarski</a> (<a href="/recipes/tags/threads/">threads</a>). Revision 8. </p> <p>This recipe shows how to profile threads in Python by using custom profiler function.</p> Closures For Highly Readable Sequence Sorting Customization (Python) 2006-01-25T03:25:24-08:00Zoran Isailovskihttp://code.activestate.com/recipes/users/2400454/http://code.activestate.com/recipes/466335-closures-for-highly-readable-sequence-sorting-cust/ <p style="color: grey"> Python recipe 466335 by <a href="/recipes/users/2400454/">Zoran Isailovski</a> (<a href="/recipes/tags/oop/">oop</a>). Revision 6. </p> <p>Whenever I feel the impulse to write a class, I pause for a moment and think whether I can get away with a closure. This time I will be using closures to readably and flexibly customize the sorting of sequences (for Pythons 2.1 through 2.3).</p> Sudoku solver (Python) 2006-02-11T16:49:17-08:00Artur de Sousa Rochahttp://code.activestate.com/recipes/users/343771/http://code.activestate.com/recipes/473844-sudoku-solver/ <p style="color: grey"> Python recipe 473844 by <a href="/recipes/users/343771/">Artur de Sousa Rocha</a> (<a href="/recipes/tags/algorithms/">algorithms</a>). Revision 3. </p> <p>This program is a Sudoku solver that uses 3 simple algorithms.</p> Read flash video (.flv files) metadata (Python) 2005-11-21T20:48:07-08:00Matthew Sherbornehttp://code.activestate.com/recipes/users/2545860/http://code.activestate.com/recipes/457406-read-flash-video-flv-files-metadata/ <p style="color: grey"> Python recipe 457406 by <a href="/recipes/users/2545860/">Matthew Sherborne</a> (<a href="/recipes/tags/web/">web</a>). </p> <p>How to read metadata from flash video files (height, width, etc.)</p> <p>Code oringinally stolen / ported from <a href="http://inlet-media.de/flvtool2" rel="nofollow">http://inlet-media.de/flvtool2</a></p> Yaptoo (Yaptu outrageously obfuscated) - or yet yet another templating utility (Python) 2006-11-15T16:58:11-08:00Michael Palmerhttp://code.activestate.com/recipes/users/1827292/http://code.activestate.com/recipes/465508-yaptoo-yaptu-outrageously-obfuscated-or-yet-yet-an/ <p style="color: grey"> Python recipe 465508 by <a href="/recipes/users/1827292/">Michael Palmer</a> (<a href="/recipes/tags/web/">web</a>). Revision 10. </p> <p>An enhanced version of yaptu, with the following changes - separated parsing from execution - added caching of parsed templates - added some error reporting - added a choice of template syntaxes - added comment syntax - added Cheetah-style variable substitution with optional caching of the equivalent Python expression - limited flow control to 'for' and 'if' Reasonably small, no external dependencies, pretty fast.</p> threaded multipart FTP download via REST (Python) 2008-09-25T19:04:08-07:00Justin Ezequielhttp://code.activestate.com/recipes/users/2717831/http://code.activestate.com/recipes/465531-threaded-multipart-ftp-download-via-rest/ <p style="color: grey"> Python recipe 465531 by <a href="/recipes/users/2717831/">Justin Ezequiel</a> (<a href="/recipes/tags/network/">network</a>). Revision 3. </p> <p>Uses Queue module from Python 2.5. Actually still running 2.4 but just dropped in the module from a 2.5 installation.</p> Parse Command Line String from CommandLine or String given base on windows OS (Python) 2007-05-18T02:01:32-07:00cheeng shu chinhttp://code.activestate.com/recipes/users/163970/http://code.activestate.com/recipes/436187-parse-command-line-string-from-commandline-or-stri/ <p style="color: grey"> Python recipe 436187 by <a href="/recipes/users/163970/">cheeng shu chin</a> (<a href="/recipes/tags/sysadmin/">sysadmin</a>). Revision 3. </p> <p>This is a way to parse command line from user provided string or try to get the original Argv from Windows OS Platform.</p> Generic proxy object with before/after method hooks. (Python) 2005-02-07T22:52:49-08:00Martin Blaishttp://code.activestate.com/recipes/users/1643324/http://code.activestate.com/recipes/366254-generic-proxy-object-with-beforeafter-method-hooks/ <p style="color: grey"> Python recipe 366254 by <a href="/recipes/users/1643324/">Martin Blais</a> . </p> <p>A proxy object that delegates method calls to an instance, but that also calls hooks for that method on the proxy, or for all methods. This can be used to implement logging of all method calls and values on an instance.</p>