Popular recipes tagged "meta:loc=131"http://code.activestate.com/recipes/tags/meta:loc=131/2017-03-10T16:34:49-08:00ActiveState Code RecipesSimple Tkinter strip chart (Python 3) (Python) 2017-03-10T16:34:49-08:00Ronaldhttp://code.activestate.com/recipes/users/4189912/http://code.activestate.com/recipes/578871-simple-tkinter-strip-chart-python-3/ <p style="color: grey"> Python recipe 578871 by <a href="/recipes/users/4189912/">Ronald</a> (<a href="/recipes/tags/chart/">chart</a>, <a href="/recipes/tags/strip/">strip</a>). Revision 3. </p> <p>This is a very simple example of how to implement a Strip Chart in Tkinter. It's somewhat slow. I've done a few things to help with performance but more could probably be done.</p> Merge multiple (potentially infinite) sorted inputs into a single sorted output (Python) 2010-04-01T04:54:16-07:00Gabriel Genellinahttp://code.activestate.com/recipes/users/924636/http://code.activestate.com/recipes/577041-merge-multiple-potentially-infinite-sorted-inputs-/ <p style="color: grey"> Python recipe 577041 by <a href="/recipes/users/924636/">Gabriel Genellina</a> (<a href="/recipes/tags/algorithm/">algorithm</a>, <a href="/recipes/tags/algorithms/">algorithms</a>, <a href="/recipes/tags/merge/">merge</a>, <a href="/recipes/tags/sort/">sort</a>). Revision 4. </p> <p>Merge a (possibly infinite) number of already sorted inputs (each of possibly infinite length) into a single sorted output.</p> <p>Similar to heapq.merge and sorted(itertools.chain(*iterables)).</p> <p>Like heapq.merge, returns a generator, does not pull the data into memory all at once, and assumes that each of the input iterables is already sorted (smallest to largest).</p> <p>Unlike heapq.merge, accepts an infinite number of input iterables, but requires all of them to come in ascending order (that is, their starting point must come in ascending order).</p> <p>In addition, accepts a <em>key</em> function (like <code>sorted</code>, <code>min</code>, <code>max</code>, etc.)</p> Bible Verse Quiz - database.py (Python) 2010-02-12T04:22:59-08:00Stephen Chappellhttp://code.activestate.com/recipes/users/2608421/http://code.activestate.com/recipes/577052-bible-verse-quiz-databasepy/ <p style="color: grey"> Python recipe 577052 by <a href="/recipes/users/2608421/">Stephen Chappell</a> (<a href="/recipes/tags/bible/">bible</a>, <a href="/recipes/tags/quiz/">quiz</a>, <a href="/recipes/tags/verse/">verse</a>, <a href="/recipes/tags/_versematch_/">_versematch_</a>). Revision 2. </p> <p>Serve verses from the Bible in response to SQL queries.</p> <p>Pulling Bible verses out of a database allows query details to be abstracted away and powerful Verse objects returned to the caller.</p> Searching .dll and .exe files in PATH (Python) 2014-10-06T09:22:53-07:00Michal Niklashttp://code.activestate.com/recipes/users/186902/http://code.activestate.com/recipes/576522-searching-dll-and-exe-files-in-path/ <p style="color: grey"> Python recipe 576522 by <a href="/recipes/users/186902/">Michal Niklas</a> (<a href="/recipes/tags/dll/">dll</a>, <a href="/recipes/tags/exe/">exe</a>, <a href="/recipes/tags/file/">file</a>, <a href="/recipes/tags/version/">version</a>, <a href="/recipes/tags/windows/">windows</a>). Revision 7. </p> <p>Returns the pathnames of the file (.exe or .dll) which would be loaded/executed in the current environment. It uses some dirs from configuration (SystemDir, WindowsDir) and dirs from PATH.</p> <p>To obtain version info it uses code from: <a href="http://pywin32.hg.sourceforge.net/hgweb/pywin32/pywin32/file/tip/win32/Demos/getfilever.py" rel="nofollow">http://pywin32.hg.sourceforge.net/hgweb/pywin32/pywin32/file/tip/win32/Demos/getfilever.py</a></p> <p>Example of usage:</p> <pre class="prettyprint"><code> c:\tools\pyscripts\scripts&gt;which_dll.py libpq.dll 2008-06-09 02:58:26 167936 [b] c:\postgresql\8.3\bin\libpq.dll ver:8.3.3.8160 2008-03-17 01:47:50 167936 [b] c:\tools\libpq.dll ver:8.3.1.8075 2008-03-17 01:47:50 167936 [b] g:\public\libpq.dll ver:8.3.1.8075 trying to load "libpq.dll" ... c:\postgresql\8.3\bin\libpq.dll loaded </code></pre> aebovl - Automatic Exposure Bracket Image Overlay (Python) 2007-05-12T19:19:44-07:00Jim Egglestonhttp://code.activestate.com/recipes/users/2894856/http://code.activestate.com/recipes/519636-aebovl-automatic-exposure-bracket-image-overlay/ <p style="color: grey"> Python recipe 519636 by <a href="/recipes/users/2894856/">Jim Eggleston</a> (<a href="/recipes/tags/graphics/">graphics</a>). </p> <p>aebovl is a script that overlays images of the same scene taken at different exposures. This brightens under-exposed areas and darkens over-exposed areas of the image. This generates a kind of poor man's HDR image.</p> Nicely readable timedelta (Python) 2006-09-02T17:18:55-07:00Björn Lindqvisthttp://code.activestate.com/recipes/users/2204911/http://code.activestate.com/recipes/498062-nicely-readable-timedelta/ <p style="color: grey"> Python recipe 498062 by <a href="/recipes/users/2204911/">Björn Lindqvist</a> . </p> <p>You want to use nicely formatted timedeltas as an alternative to using absolute dates. Instead of writing "Last modified 2006-07-01" you want that to read "Modified two months ago" Or you are working for a credit card company and you want to send threatening letters; "Dear sir or madam, two weeks ago we contacted you about your overdue credit..."</p> z_service.py (Python) 2006-07-07T11:09:57-07:00Stephen Chappellhttp://code.activestate.com/recipes/users/2608421/http://code.activestate.com/recipes/496872-z_servicepy/ <p style="color: grey"> Python recipe 496872 by <a href="/recipes/users/2608421/">Stephen Chappell</a> (<a href="/recipes/tags/network/">network</a>). </p> <p>This recipe allows the creation of servers that provide services to connecting programs. This is basically a remote procedure call (RPC) server that allows various clients to connect and communicate through registered functions.</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> Wrapper class for the heapq module (Python) 2005-07-19T06:36:56-07:00Allen Downeyhttp://code.activestate.com/recipes/users/2523263/http://code.activestate.com/recipes/437116-wrapper-class-for-the-heapq-module/ <p style="color: grey"> Python recipe 437116 by <a href="/recipes/users/2523263/">Allen Downey</a> (<a href="/recipes/tags/oop/">oop</a>). </p> <p>For people who prefer object-oriented style, this wrapper class provides a cleaner interface to the functions in the heapq module. It also provides some additional capabilities, including reduce, which is useful in some graph algorithms.</p> The End of Inheritance: Automatic Run-time Interface Building for Aggregated Objects (Python) 2002-09-15T16:20:13-07:00Paul Baranowskihttp://code.activestate.com/recipes/users/689044/http://code.activestate.com/recipes/149878-the-end-of-inheritance-automatic-run-time-interfac/ <p style="color: grey"> Python recipe 149878 by <a href="/recipes/users/689044/">Paul Baranowski</a> (<a href="/recipes/tags/programs/">programs</a>). </p> <p>"Design Patterns" [GoF] prescribes two commandments to live by:</p> <p>1) Program to an interface, not an implementation. 2) Favor object composition over class inheritance.</p> <p>This implies that every class should have a defined interface, and that every class should be a composition of objects. However, there is often a large barrier to object composition - sometimes a class needs to have the interface of its components. You don't want to extend the functionality of the component, you just want its interface, and you want all calls to that interface to be sent to the component object. In this case, it is so much easier to inherit even though you are not really extending the functionality of the parent class (this especially happens when writing GUI applications, where the components have huge APIs). If you bite the bullet and make a composite, you end up writing a lot of wrapper functions (see Figure 1). (A wrapper function has the same function signature as the function it is wrapping, and it simply calls the same function in the target object.) No one likes to write wrapper functions - its dull, boring, menial work. I've thrown out plenty of my own designs because they would have required me to write wrappers for a huge number of functions (for example, the wxWindow class has over 130 member functions. See <a href="http://www.wxWindows.org" rel="nofollow">http://www.wxWindows.org</a>), so I end up inheriting even though I know it is "wrong".</p> <p>There is no way around this problem in C++ and Java (though maybe an IDE vendor could put in a tool to automatically generate wrapper functions). Amazingly enough, however, Python allows you to modify classes at run time. This means it is possible to make Python automatically write these wrapper (or proxy) functions for you.</p> Null Object Design Pattern (Python) 2001-09-07T00:14:12-07:00Dinu Ghermanhttp://code.activestate.com/recipes/users/124101/http://code.activestate.com/recipes/68205-null-object-design-pattern/ <p style="color: grey"> Python recipe 68205 by <a href="/recipes/users/124101/">Dinu Gherman</a> (<a href="/recipes/tags/oop/">oop</a>). </p> <p>Null objects are intended to provide first-class citizens as a replacement for the primitive value None. Using them you can avoid conditional statements in your code and express algorithms with less checking for special values.</p> Flexible string splitting/parsing routine (Tcl) 2005-07-06T06:44:26-07:00Joe Mistachkinhttp://code.activestate.com/recipes/users/141324/http://code.activestate.com/recipes/116653-flexible-string-splittingparsing-routine/ <p style="color: grey"> Tcl recipe 116653 by <a href="/recipes/users/141324/">Joe Mistachkin</a> (<a href="/recipes/tags/text/">text</a>). Revision 2. </p> <p>This routine allows you to split a string on multiple characters. Additionally, you can specify the maximum number of elements to return. The final element will contain the remainder of the string.</p> Saving backups when writing files (Python) 2001-05-08T23:12:33-07:00Mitch Chapmanhttp://code.activestate.com/recipes/users/98085/http://code.activestate.com/recipes/52277-saving-backups-when-writing-files/ <p style="color: grey"> Python recipe 52277 by <a href="/recipes/users/98085/">Mitch Chapman</a> . Revision 2. </p> <p>Before overwriting an existing file it's often desirable to make a backup. This recipe emulates the behavior of Emacs by saving versioned backups. It's also compatible with the marshal module, so you can save versioned output in "marshal" format.</p>