Popular recipes tagged "meta:loc=68"http://code.activestate.com/recipes/tags/meta:loc=68/2016-01-27T22:22:01-08:00ActiveState Code RecipesSimple drawing tool with Python turtle graphics (Python) 2016-01-27T22:22:01-08:00Vasudev Ramhttp://code.activestate.com/recipes/users/4173351/http://code.activestate.com/recipes/580544-simple-drawing-tool-with-python-turtle-graphics/ <p style="color: grey"> Python recipe 580544 by <a href="/recipes/users/4173351/">Vasudev Ram</a> (<a href="/recipes/tags/drawing/">drawing</a>, <a href="/recipes/tags/graphics/">graphics</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/python2/">python2</a>, <a href="/recipes/tags/tkinter/">tkinter</a>, <a href="/recipes/tags/turtle/">turtle</a>). </p> <p>A simple drawing program that lets you use your keyboard to draw figures on screen, using the turtle graphics module built into Python.</p> Wrap a a file-like object in another that calls a user callback whenever read() is called on it. (Python) 2013-09-25T01:54:53-07:00Martin Millerhttp://code.activestate.com/recipes/users/155538/http://code.activestate.com/recipes/578674-wrap-a-a-file-like-object-in-another-that-calls-a-/ <p style="color: grey"> Python recipe 578674 by <a href="/recipes/users/155538/">Martin Miller</a> (<a href="/recipes/tags/callback/">callback</a>, <a href="/recipes/tags/file/">file</a>, <a href="/recipes/tags/oop/">oop</a>, <a href="/recipes/tags/progress/">progress</a>, <a href="/recipes/tags/upload/">upload</a>). </p> <p>Wraps a file-like object in another, but also calls a user callback with the number of bytes read whenever its <code>read()</code> method is called. Used for tracking upload progress, for example for a progress bar in a UI application.</p> Python single instance (cross-platform) (Python) 2013-02-10T16:22:33-08:00Esteban Castro Borsanihttp://code.activestate.com/recipes/users/4184010/http://code.activestate.com/recipes/578453-python-single-instance-cross-platform/ <p style="color: grey"> Python recipe 578453 by <a href="/recipes/users/4184010/">Esteban Castro Borsani</a> (<a href="/recipes/tags/application/">application</a>, <a href="/recipes/tags/instance/">instance</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/single/">single</a>, <a href="/recipes/tags/singleton/">singleton</a>). </p> <p>Yet another way to get a single instance application. This recipe uses file locking only.</p> Python single instance (cross-platform) (Python) 2013-02-28T04:14:08-08:00Deepakhttp://code.activestate.com/recipes/users/4183429/http://code.activestate.com/recipes/578476-python-single-instance-cross-platform/ <p style="color: grey"> Python recipe 578476 by <a href="/recipes/users/4183429/">Deepak</a> (<a href="/recipes/tags/application/">application</a>, <a href="/recipes/tags/instance/">instance</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/single/">single</a>, <a href="/recipes/tags/singleton/">singleton</a>). </p> <p>Yet another way to get a single instance application. This recipe uses file locking only.</p> safetkinter.py (Python) 2012-06-05T03:23:47-07:00Stephen Chappellhttp://code.activestate.com/recipes/users/2608421/http://code.activestate.com/recipes/578153-safetkinterpy/ <p style="color: grey"> Python recipe 578153 by <a href="/recipes/users/2608421/">Stephen Chappell</a> (<a href="/recipes/tags/threadsafe/">threadsafe</a>, <a href="/recipes/tags/tkinter/">tkinter</a>). </p> <p>Register tkinter classes with threadbox for immediate usage.</p> <p>This module clones several classes from the tkinter library for use with threads. Instances from these new classes should run on whatever thread the root was created on. Child classes inherit the parent's safety.</p> CleanupManager for with statements (Python) 2011-12-18T07:20:46-08:00Nick Coghlanhttp://code.activestate.com/recipes/users/2035254/http://code.activestate.com/recipes/577981-cleanupmanager-for-with-statements/ <p style="color: grey"> Python recipe 577981 by <a href="/recipes/users/2035254/">Nick Coghlan</a> (<a href="/recipes/tags/contextmanager/">contextmanager</a>, <a href="/recipes/tags/context_manager/">context_manager</a>). Revision 5. </p> <p>Inspired by unittest.TestCase.addCleanup(), CleanupManager provides a means to programmatically add resources to be cleaned up when leaving a with statement. This makes it easy to use with optional resources, and those derived from sequences of inputs.</p> <p>An more powerful version of this recipe with a few additional features is published under the name <code>ContextStack</code> as part of the contextlib2 module: <a href="http://contextlib2.readthedocs.org" rel="nofollow">http://contextlib2.readthedocs.org</a></p> <p>This recipe is based on a suggestion originally posted by Nikolaus Rath at <a href="http://bugs.python.org/issue13585" rel="nofollow">http://bugs.python.org/issue13585</a></p> ActiveState recipe importer (Python) 2011-11-23T02:27:51-08:00nosklohttp://code.activestate.com/recipes/users/4166478/http://code.activestate.com/recipes/577958-activestate-recipe-importer/ <p style="color: grey"> Python recipe 577958 by <a href="/recipes/users/4166478/">nosklo</a> (<a href="/recipes/tags/activestate/">activestate</a>, <a href="/recipes/tags/code/">code</a>, <a href="/recipes/tags/import/">import</a>, <a href="/recipes/tags/library/">library</a>). </p> <p>Finally! This code allows you to import any activestate recipe right into your code!</p> <p>Example:</p> <pre class="prettyprint"><code>&gt;&gt;&gt; from activestate.recipe194373 import mreplace &gt;&gt;&gt; print mreplace('ectave steta racipas rock!', ('a', 'e'), ('e', 'a')) active state recipes rock! </code></pre> <p>Save this as <strong>activestate.py</strong></p> Deprecated decorator (Python) 2013-12-14T01:24:31-08:00Giampaolo RodolĂ http://code.activestate.com/recipes/users/4178764/http://code.activestate.com/recipes/577819-deprecated-decorator/ <p style="color: grey"> Python recipe 577819 by <a href="/recipes/users/4178764/">Giampaolo RodolĂ </a> (<a href="/recipes/tags/decorator/">decorator</a>, <a href="/recipes/tags/deprecated/">deprecated</a>, <a href="/recipes/tags/python/">python</a>). Revision 3. </p> <p>A decorator to deprecate a function and provide a new one as replacement.</p> Multiprocessing import wrapper (Python) 2011-08-23T22:11:42-07:00Matt Keranenhttp://code.activestate.com/recipes/users/38288/http://code.activestate.com/recipes/577856-multiprocessing-import-wrapper/ <p style="color: grey"> Python recipe 577856 by <a href="/recipes/users/38288/">Matt Keranen</a> (<a href="/recipes/tags/database/">database</a>, <a href="/recipes/tags/etl/">etl</a>, <a href="/recipes/tags/import/">import</a>, <a href="/recipes/tags/multiprocessing/">multiprocessing</a>). Revision 2. </p> <p>A script used to launch multiple import scripts using the multiprocessing module. Developed to parallelize loading of multiple log files into a database for aggregate analysis</p> Function Pipelines (Python) 2011-05-22T20:39:05-07:00Rob Lhttp://code.activestate.com/recipes/users/4178061/http://code.activestate.com/recipes/577714-function-pipelines/ <p style="color: grey"> Python recipe 577714 by <a href="/recipes/users/4178061/">Rob L</a> (<a href="/recipes/tags/events/">events</a>, <a href="/recipes/tags/pipelining/">pipelining</a>, <a href="/recipes/tags/wsgi/">wsgi</a>). </p> <p>Alexandre Zani's recipe on function pipelines was useful. I wanted to change it to suit my needs.</p> <p>Mostly I just wanted to add arbitrary functions and make the pipe line more list like in behavior.</p> <p>(edit: typos)</p> Python Infinite Rotations and Tails (Python) 2011-02-13T15:27:42-08:00Thomas Ahlehttp://code.activestate.com/recipes/users/4060075/http://code.activestate.com/recipes/577574-python-infinite-rotations-and-tails/ <p style="color: grey"> Python recipe 577574 by <a href="/recipes/users/4060075/">Thomas Ahle</a> (<a href="/recipes/tags/cycles/">cycles</a>, <a href="/recipes/tags/functional/">functional</a>, <a href="/recipes/tags/infinite/">infinite</a>, <a href="/recipes/tags/lists/">lists</a>, <a href="/recipes/tags/rotations/">rotations</a>, <a href="/recipes/tags/tails/">tails</a>). </p> <p>This is an example of how functional ideas of infinite lists can be used in python to optimize memory usage of certain problems.</p> Aggregates using groupby, defaultdict and Counter (Python) 2011-02-07T15:38:09-08:00N Nhttp://code.activestate.com/recipes/users/1639254/http://code.activestate.com/recipes/577535-aggregates-using-groupby-defaultdict-and-counter/ <p style="color: grey"> Python recipe 577535 by <a href="/recipes/users/1639254/">N N</a> (<a href="/recipes/tags/algorithms/">algorithms</a>). Revision 2. </p> <p>How to emulate SQL aggregate functions AVG, COUNT, MAX, MIN and SUM on csv type data files using tools from the standard library.</p> Koch Snowflake and Sierpinski Triangle Combination Fractal (Python) 2010-03-27T03:24:35-07:00FB36http://code.activestate.com/recipes/users/4172570/http://code.activestate.com/recipes/577156-koch-snowflake-and-sierpinski-triangle-combination/ <p style="color: grey"> Python recipe 577156 by <a href="/recipes/users/4172570/">FB36</a> (<a href="/recipes/tags/fractal/">fractal</a>, <a href="/recipes/tags/graphics/">graphics</a>, <a href="/recipes/tags/image/">image</a>, <a href="/recipes/tags/math/">math</a>). </p> <p>Koch Snowflake and Sierpinski Triangle Combination Fractal using recursion.</p> write_path and load_path methods for file generation scripts (Python) 2010-07-27T06:45:51-07:00Trent Mickhttp://code.activestate.com/recipes/users/4173505/http://code.activestate.com/recipes/577172-write_path-and-load_path-methods-for-file-generati/ <p style="color: grey"> Python recipe 577172 by <a href="/recipes/users/4173505/">Trent Mick</a> (<a href="/recipes/tags/files/">files</a>). Revision 7. </p> <p>I have a lot of scripts that end up writing files (often build system stuff). Everytime I either end up writing the obvious quick <code>content = open(path).read()</code> or I re-implement a function that handles things like: making a backup, some typical logging, encoding support, trying to make it no-op if no changes, etc.</p> <p>In this recipe I'll try to add a number of these features so I don't have to keep re-writing this. :) So far this is just a start.</p> <p>Current features:</p> <ul> <li>rudimentary <code>encoding</code> support</li> <li>logging on a given <code>log</code> argument</li> <li><code>create_backup</code> argument to create a backup file</li> <li>writes to a temporary file and uses atomic <code>os.rename</code> to avoid destroying the existing file if writing fails</li> </ul> Generate HTML syntax-highlighted listings for any file using pygments (Python) 2011-02-01T14:21:59-08:00ccpizzahttp://code.activestate.com/recipes/users/4170754/http://code.activestate.com/recipes/576812-generate-html-syntax-highlighted-listings-for-any-/ <p style="color: grey"> Python recipe 576812 by <a href="/recipes/users/4170754/">ccpizza</a> (<a href="/recipes/tags/pretty_printer/">pretty_printer</a>, <a href="/recipes/tags/pygments/">pygments</a>, <a href="/recipes/tags/syntax_highlighter/">syntax_highlighter</a>). Revision 6. </p> <p>Generates HTML highlighted code listings for source code files in any language known to pygments. For a list of supported formats see <a href="http://pygments.org/languages" rel="nofollow">http://pygments.org/languages</a></p> <p>Make sure you have <a href="http://pygments.org">pygments</a> is installed. Try <code>easy_install pygments</code>.</p> <p>Example usage:</p> <p><em>output to stdout:</em></p> <pre class="prettyprint"><code>python highlight.py my_source_file.java </code></pre> <p><em>output to file:</em></p> <pre class="prettyprint"><code>python highlight.py my_source_file.java &gt; my_source_file.html </code></pre> Calculations on huge (memmap-)arrays (Python) 2009-05-05T10:19:37-07:00d.schlabinghttp://code.activestate.com/recipes/users/4168903/http://code.activestate.com/recipes/576739-calculations-on-huge-memmap-arrays/ <p style="color: grey"> Python recipe 576739 by <a href="/recipes/users/4168903/">d.schlabing</a> (<a href="/recipes/tags/memmap/">memmap</a>, <a href="/recipes/tags/numpy/">numpy</a>, <a href="/recipes/tags/oop/">oop</a>). Revision 2. </p> <p>This is a way of doing calculations on whole arrays that might be to big to fit into memory.</p> Skype chat to speech (Python) 2009-01-25T13:47:33-08:00nigel spinneyhttp://code.activestate.com/recipes/users/4113342/http://code.activestate.com/recipes/576626-skype-chat-to-speech/ <p style="color: grey"> Python recipe 576626 by <a href="/recipes/users/4113342/">nigel spinney</a> (<a href="/recipes/tags/chat/">chat</a>, <a href="/recipes/tags/espeak/">espeak</a>, <a href="/recipes/tags/skype/">skype</a>, <a href="/recipes/tags/text_to_speech/">text_to_speech</a>, <a href="/recipes/tags/ubuntu/">ubuntu</a>). </p> <p>Using espeak text to speech in Ubuntu, and the skype4py module, this will read out the contents of chat messages recieved-created to help me when away from my PC so if i have my hands full with the younger members of my family I can decide how urgent the chat is without having to go near the computer.</p> Illustration: Writing a TappedIn.com calendar item from FeedDemon to Google Calendar (Python) 2009-01-03T17:13:46-08:00Bill Bellhttp://code.activestate.com/recipes/users/4168674/http://code.activestate.com/recipes/576604-illustration-writing-a-tappedincom-calendar-item-f/ <p style="color: grey"> Python recipe 576604 by <a href="/recipes/users/4168674/">Bill Bell</a> (<a href="/recipes/tags/blog_publisher/">blog_publisher</a>, <a href="/recipes/tags/feeddemon/">feeddemon</a>, <a href="/recipes/tags/google_calendar/">google_calendar</a>, <a href="/recipes/tags/tappedin/">tappedin</a>). </p> <p>This recipe is for reference purposes. It indicates how the FeedDemon RSS reader supplies information about a post to a blog publisher application under the default arrangements (ie, without specifying XML), and then how this information can be reformatted for a <a href="http://TappedIn.com" rel="nofollow">TappedIn.com</a> calendar item for submission to the Google Calendar. Nothing unusual but might be useful to people who use FeedDemon and want to record TappedIn sessions on Google (obviously).</p> Yet another signal/slot implementation in Python (Python) 2008-09-01T23:21:28-07:00Thiago Marcos P. Santoshttp://code.activestate.com/recipes/users/4166797/http://code.activestate.com/recipes/576477-yet-another-signalslot-implementation-in-python/ <p style="color: grey"> Python recipe 576477 by <a href="/recipes/users/4166797/">Thiago Marcos P. Santos</a> (<a href="/recipes/tags/observer/">observer</a>, <a href="/recipes/tags/publish/">publish</a>, <a href="/recipes/tags/signal/">signal</a>, <a href="/recipes/tags/slot/">slot</a>, <a href="/recipes/tags/subscribe/">subscribe</a>, <a href="/recipes/tags/weakref/">weakref</a>). </p> <p>This code snippet was based on the nice <a href="http://code.activestate.com/recipes/439356/">recipe 439356</a> made by Patrick Chasco. My implementation supports only class methods callbacks. I'm keeping the idea of use weakrefs to avoid the interpreter keep the object allocated because the signal is registered (i.e. the signal object holds a reference to callback method). IMO the usage of WeakValueDictionary made the code smaller and clear and also are maintenance-free (when the object is collect by the garbage collector the signal is automatically unregistered). </p> lpr-based printer module for *nix (Python) 2007-04-30T06:34:39-07:00Andrew Moffathttp://code.activestate.com/recipes/users/2979564/http://code.activestate.com/recipes/511505-lpr-based-printer-module-for-nix/ <p style="color: grey"> Python recipe 511505 by <a href="/recipes/users/2979564/">Andrew Moffat</a> (<a href="/recipes/tags/text/">text</a>). </p> <p>a very simple printer module for any *nix system that has lpr</p>