Popular recipes tagged "meta:min_python_2=5"http://code.activestate.com/recipes/tags/meta:min_python_2=5/2014-11-08T19:10:58-08:00ActiveState Code RecipesA memoize decorator for instance methods (Python)
2010-11-04T20:23:35-07:00Daniel Millerhttp://code.activestate.com/recipes/users/4016391/http://code.activestate.com/recipes/577452-a-memoize-decorator-for-instance-methods/
<p style="color: grey">
Python
recipe 577452
by <a href="/recipes/users/4016391/">Daniel Miller</a>
(<a href="/recipes/tags/cache/">cache</a>, <a href="/recipes/tags/functools/">functools</a>, <a href="/recipes/tags/memoize/">memoize</a>, <a href="/recipes/tags/partial/">partial</a>).
</p>
<p>A simple result-caching decorator for instance methods. NOTE: does not work with plain old non-instance-method functions. The cache is stored on the instance to prevent memory leaks caused by long-term caching beyond the life of the instance (almost all other recipes I found suffer from this problem when used with instance methods).</p>
Not Quite So Simple QuickTime Player, Python Audio Capture. (Python)
2014-11-08T19:10:58-08:00Barry Walkerhttp://code.activestate.com/recipes/users/4177147/http://code.activestate.com/recipes/578960-not-quite-so-simple-quicktime-player-python-audio-/
<p style="color: grey">
Python
recipe 578960
by <a href="/recipes/users/4177147/">Barry Walker</a>
(<a href="/recipes/tags/apple/">apple</a>, <a href="/recipes/tags/audio/">audio</a>, <a href="/recipes/tags/audio_capture/">audio_capture</a>, <a href="/recipes/tags/capture/">capture</a>, <a href="/recipes/tags/macbook_pro/">macbook_pro</a>, <a href="/recipes/tags/maccbook_pro/">maccbook_pro</a>, <a href="/recipes/tags/sample/">sample</a>, <a href="/recipes/tags/signal_capture/">signal_capture</a>).
</p>
<p>Not Quite So Simple QuickTime Player, Python Audio Capture.</p>
<p>This DEMO code captures a function to generate a user 5 second Audio sample in Apple *.aifc format.
It is then converted to DC quailty *.WAV format.</p>
<p>It uses default shell system files to do the task.</p>
<p>An AppleScript is created to do the sample but due to the limitations of QT Player there is a 1.5 second delay to allow QuickTine Player to start up.
It is not entirely quiet but unobtrusive enough as to be like quiet mode...</p>
<p>This is again a means a signal capture for an AudioScope without the need for special tools or installs.</p>
<p>Read the code for more information.</p>
<p>IMPORTANT!!! This DEMO WILL delete all *.aifc files inside the default $HOME/Movies directory, so be aware.</p>
<p>A simple ALSA one is on its way too...</p>
<p>It actually works on Python 3.4.1 but I have no idea if it works below Python 2.5.6...</p>
<p>Bazza...</p>
Accordion Widget (Tkinter) (Python)
2014-07-18T11:39:51-07:00Peter Mojeikohttp://code.activestate.com/recipes/users/4190241/http://code.activestate.com/recipes/578911-accordion-widget-tkinter/
<p style="color: grey">
Python
recipe 578911
by <a href="/recipes/users/4190241/">Peter Mojeiko</a>
(<a href="/recipes/tags/gui/">gui</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/tkinter/">tkinter</a>).
</p>
<p>An expanding/collapsing widget for Tkinter.</p>
<p>usage:</p>
<pre class="prettyprint"><code>from accordion import Accordion, Chord
root = Tk()
accordion = Accordion(root)
accordion.pack()
chord1 = Chord(accordion, title='Chord')
# create widgets and give them chord1 as parent
accordion.append_chords([chord1])
root.mainloop()
</code></pre>
<p>There's a more detailed example at the bottom of the file.</p>
Python Awesome DD (Python)
2014-07-12T07:29:59-07:00Mike 'Fuzzy' Partinhttp://code.activestate.com/recipes/users/4179778/http://code.activestate.com/recipes/578907-python-awesome-dd/
<p style="color: grey">
Python
recipe 578907
by <a href="/recipes/users/4179778/">Mike 'Fuzzy' Partin</a>
(<a href="/recipes/tags/curses/">curses</a>, <a href="/recipes/tags/dd/">dd</a>, <a href="/recipes/tags/file/">file</a>, <a href="/recipes/tags/input/">input</a>, <a href="/recipes/tags/output/">output</a>, <a href="/recipes/tags/progress_bar/">progress_bar</a>).
Revision 3.
</p>
<p>Imagine if the *nix utilities 'dd', 'wget', and 'pv' had a baby. That baby would be named 'padd'. A 'dd' replacement (most commonly used options translate with no problem), that gives progress output like 'pv' and supports (currently) http(s) and ftp input sources, with more planned (sftp for one). Output support for ftp, sftp, and http(s) is also planned.</p>
SuperText - Scrollable text with pop-up menu and themes for Tkinter (Python)
2014-06-20T16:25:43-07:00Peter Mojeikohttp://code.activestate.com/recipes/users/4190241/http://code.activestate.com/recipes/578897-supertext-scrollable-text-with-pop-up-menu-and-the/
<p style="color: grey">
Python
recipe 578897
by <a href="/recipes/users/4190241/">Peter Mojeiko</a>
(<a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/text_enriched/">text_enriched</a>, <a href="/recipes/tags/tkinter/">tkinter</a>).
</p>
<p>Two things I consistently need when using a Text widget are scrollbars and pop-up menus. I've been adding them in on the fly for a while, but I think this class provides an easier way to implement these features.</p>
<p>I also added a couple of very minimal themes:</p>
<pre class="prettyprint"><code>1. The terminal theme replaces the standard Text cursor with a blocky-style
insert cursor
2. The typewriter theme takes any text that has been inserted before it is called
and types it to the widget, one character at a time
</code></pre>
<p>There's an example of use at the bottom of the code.</p>
Hartree Fock SCF (Python)
2013-04-30T09:09:20-07:00alexander bakerhttp://code.activestate.com/recipes/users/4166679/http://code.activestate.com/recipes/578515-hartree-fock-scf/
<p style="color: grey">
Python
recipe 578515
by <a href="/recipes/users/4166679/">alexander baker</a>
(<a href="/recipes/tags/numpy/">numpy</a>, <a href="/recipes/tags/physics/">physics</a>).
Revision 4.
</p>
<p>Quantum Chemistry technique to calculate various interesting operators for HeH.</p>
Publish Berkeley DB data to PDF with xtopdf (Python)
2014-01-24T17:57:21-08:00Vasudev Ramhttp://code.activestate.com/recipes/users/4173351/http://code.activestate.com/recipes/578814-publish-berkeley-db-data-to-pdf-with-xtopdf/
<p style="color: grey">
Python
recipe 578814
by <a href="/recipes/users/4173351/">Vasudev Ram</a>
(<a href="/recipes/tags/bsddb/">bsddb</a>, <a href="/recipes/tags/database/">database</a>, <a href="/recipes/tags/pdf/">pdf</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/xtopdf/">xtopdf</a>).
</p>
<p>This recipe shows how to convert the data stored in a Berkeley DB database to PDF, using the xtopdf toolkit for PDF creation.
It should work on either Linux/Unix or Windows.</p>
Simple Text Mode Digital Oscilloscope Graphics DEMO. (Python)
2014-01-21T19:07:49-08:00Barry Walkerhttp://code.activestate.com/recipes/users/4177147/http://code.activestate.com/recipes/578812-simple-text-mode-digital-oscilloscope-graphics-dem/
<p style="color: grey">
Python
recipe 578812
by <a href="/recipes/users/4177147/">Barry Walker</a>
(<a href="/recipes/tags/apple/">apple</a>, <a href="/recipes/tags/demo/">demo</a>, <a href="/recipes/tags/graphics/">graphics</a>, <a href="/recipes/tags/linux/">linux</a>, <a href="/recipes/tags/macbook_pro/">macbook_pro</a>).
</p>
<p>This is a DEMO to switch a *NIX terminal from text to _graphics_ mode on the fly.</p>
<p>The graphics characters are limited to lowercase 'a' through 'z' and
this DEMO just prints a small subset to see what a fun, kids level, 8
channel Logic-Analyser/Digital-Oscilloscope might look like.</p>
<p>This may not work in every *NIX style terminal but does work on default
terminals using bash on OSX 10.7.5, PCLinuxOS 2009 and Debian Linux 6.0.x.</p>
<p>Tested on Python 2.5.x to 3.3.2 on the above platforms...
(It might work on earlier versions of Python but untested.)</p>
<p>Enjoy finding simple solutions to often very difficult problems...</p>
<p>Bazza...</p>
Create PDF at the end of a Unix pipeline with PDFWriter (Python)
2013-12-22T22:19:00-08:00Vasudev Ramhttp://code.activestate.com/recipes/users/4173351/http://code.activestate.com/recipes/578794-create-pdf-at-the-end-of-a-unix-pipeline-with-pdfw/
<p style="color: grey">
Python
recipe 578794
by <a href="/recipes/users/4173351/">Vasudev Ram</a>
(<a href="/recipes/tags/commandline/">commandline</a>, <a href="/recipes/tags/linux/">linux</a>, <a href="/recipes/tags/pdf/">pdf</a>, <a href="/recipes/tags/pipelining/">pipelining</a>, <a href="/recipes/tags/reportlab/">reportlab</a>, <a href="/recipes/tags/unix/">unix</a>, <a href="/recipes/tags/xtopdf/">xtopdf</a>).
</p>
<p>This recipe shows how to create PDF output at the end of a Unix or Linux pipeline, after all the text processing required, is done by previous components of the pipeline (which can use any of the standard tools of Unix such as sed, grep, awk, etc., as well as custom programs that act as filters).</p>
Priority Queue (with deletion) (Python)
2013-12-08T21:12:55-08:00elazarhttp://code.activestate.com/recipes/users/4187847/http://code.activestate.com/recipes/578780-priority-queue-with-deletion/
<p style="color: grey">
Python
recipe 578780
by <a href="/recipes/users/4187847/">elazar</a>
(<a href="/recipes/tags/artificial_intelligence/">artificial_intelligence</a>, <a href="/recipes/tags/heap/">heap</a>, <a href="/recipes/tags/heapq/">heapq</a>, <a href="/recipes/tags/priority_queue/">priority_queue</a>, <a href="/recipes/tags/queue/">queue</a>).
Revision 5.
</p>
<p>Based on the interface defined in aima-python
<a href="http://aima-python.googlecode.com/svn/trunk/utils.py" rel="nofollow">http://aima-python.googlecode.com/svn/trunk/utils.py</a></p>
<p>Yields better performance.</p>
Easy Bit Arrays using Long Integers (Python)
2013-12-01T02:21:14-08:00Mike Sweeneyhttp://code.activestate.com/recipes/users/4177990/http://code.activestate.com/recipes/578777-easy-bit-arrays-using-long-integers/
<p style="color: grey">
Python
recipe 578777
by <a href="/recipes/users/4177990/">Mike Sweeney</a>
(<a href="/recipes/tags/array/">array</a>, <a href="/recipes/tags/bit/">bit</a>, <a href="/recipes/tags/bitwise/">bitwise</a>, <a href="/recipes/tags/integer/">integer</a>, <a href="/recipes/tags/long/">long</a>).
</p>
<p>Some simple techniques for working with long integers as bit arrays. Python support for long integers allows fast bitwise operations on large bit arrays. Bitwise operations on 100 million bit arrays happen in the blink of an eye. They are also fast and compact when saving and loading to disk. Unfortunately bit set, get, append, pop etc are slow so another bit array technique may be preferred.</p>
A DEMO to show how to write text into the Python terminal Title Bar... (Python)
2013-09-17T17:55:53-07:00Barry Walkerhttp://code.activestate.com/recipes/users/4177147/http://code.activestate.com/recipes/578662-a-demo-to-show-how-to-write-text-into-the-python-t/
<p style="color: grey">
Python
recipe 578662
by <a href="/recipes/users/4177147/">Barry Walker</a>
(<a href="/recipes/tags/apple/">apple</a>, <a href="/recipes/tags/bar/">bar</a>, <a href="/recipes/tags/cygwin/">cygwin</a>, <a href="/recipes/tags/demo/">demo</a>, <a href="/recipes/tags/linux/">linux</a>, <a href="/recipes/tags/macbook_pro/">macbook_pro</a>, <a href="/recipes/tags/title/">title</a>, <a href="/recipes/tags/title_bar/">title_bar</a>).
</p>
<p>This DEMO is show how to write some text of your choice into the Title Bar of the Python terminal window.</p>
<p>Firstly it imports "time" just for this demo so that a simple time delay can be generated.
Next the Python terminal window is written to for the 5 seconds of delay; see code.
And finally the Title Bar is restored to normal...</p>
<p>A snapshot image can be seen here:-</p>
<p><a href="http://wisecracker.host22.com/public/Title_Bar.jpg" rel="nofollow">http://wisecracker.host22.com/public/Title_Bar.jpg</a></p>
<p>Bazza...</p>
FreshFish (Python)
2013-12-29T15:38:33-08:00Justin Shawhttp://code.activestate.com/recipes/users/1523109/http://code.activestate.com/recipes/578800-freshfish/
<p style="color: grey">
Python
recipe 578800
by <a href="/recipes/users/1523109/">Justin Shaw</a>
.
Revision 2.
</p>
<p>FreshFish is a function decorator for functions with no arguments (hardware query).</p>
<p>The first time the function is called, the wrapper caches the result (the fish). Subsequent calls to the wrapped function simply return the cached result as long as the fish is still fresh. When the fish goes stale, FreshFish calls the underlying function again for FreshFish.</p>
<p>I used this on a BeagleBone project to monitor heart rate, speed, and cadence.</p>
Bell permutations using Even's nonrecursive algorithm (Python)
2013-12-23T02:44:43-08:00Chris Smithhttp://code.activestate.com/recipes/users/2725752/http://code.activestate.com/recipes/578792-bell-permutations-using-evens-nonrecursive-algorit/
<p style="color: grey">
Python
recipe 578792
by <a href="/recipes/users/2725752/">Chris Smith</a>
(<a href="/recipes/tags/bell/">bell</a>, <a href="/recipes/tags/johnson/">johnson</a>, <a href="/recipes/tags/permutations/">permutations</a>, <a href="/recipes/tags/steinhaus/">steinhaus</a>, <a href="/recipes/tags/trotter/">trotter</a>).
Revision 2.
</p>
<p>The "bell" permutations are those in which only a single inversion of neighbors occurs to generate the next permutation.</p>
Generator with lookahead (Python)
2013-09-24T10:44:56-07:00Rutger Saalminkhttp://code.activestate.com/recipes/users/4187940/http://code.activestate.com/recipes/578671-generator-with-lookahead/
<p style="color: grey">
Python
recipe 578671
by <a href="/recipes/users/4187940/">Rutger Saalmink</a>
(<a href="/recipes/tags/background/">background</a>, <a href="/recipes/tags/generator/">generator</a>, <a href="/recipes/tags/generators/">generators</a>, <a href="/recipes/tags/lookahead/">lookahead</a>, <a href="/recipes/tags/performance/">performance</a>, <a href="/recipes/tags/python/">python</a>).
</p>
<p>Python generators are a great way of reducing memory usage due to the lazy (on demand) generation of values. However, when the process-time of generating such a value is relatively high, we can improve performance even more by obtaining the next n values of the generator in a separate thread in the background. Hence, the BackgroundGenerator.</p>
adventure game base (Python)
2013-08-03T20:51:02-07:00Andrew Wayne Teesdale Jr.http://code.activestate.com/recipes/users/4187305/http://code.activestate.com/recipes/578623-adventure-game-base/
<p style="color: grey">
Python
recipe 578623
by <a href="/recipes/users/4187305/">Andrew Wayne Teesdale Jr.</a>
(<a href="/recipes/tags/base_class/">base_class</a>, <a href="/recipes/tags/text_game/">text_game</a>).
</p>
<p>simple module that holds the needed classes to make an adventure game
plus a ascii anamation class for ascii art</p>
music module (Python)
2013-08-02T02:37:01-07:00Andrew Wayne Teesdale Jr.http://code.activestate.com/recipes/users/4187305/http://code.activestate.com/recipes/578620-music-module/
<p style="color: grey">
Python
recipe 578620
by <a href="/recipes/users/4187305/">Andrew Wayne Teesdale Jr.</a>
(<a href="/recipes/tags/beep/">beep</a>, <a href="/recipes/tags/music/">music</a>).
</p>
<p>a module for musical beeps</p>
ascii anamation using ascii anamation module (Python)
2013-08-08T19:50:40-07:00Andrew Wayne Teesdale Jr.http://code.activestate.com/recipes/users/4187305/http://code.activestate.com/recipes/578628-ascii-anamation-using-ascii-anamation-module/
<p style="color: grey">
Python
recipe 578628
by <a href="/recipes/users/4187305/">Andrew Wayne Teesdale Jr.</a>
(<a href="/recipes/tags/animation/">animation</a>).
</p>
<p>small animation using ascii</p>
ascii anamation module (Python)
2013-08-22T16:20:58-07:00Andrew Wayne Teesdale Jr.http://code.activestate.com/recipes/users/4187305/http://code.activestate.com/recipes/578622-ascii-anamation-module/
<p style="color: grey">
Python
recipe 578622
by <a href="/recipes/users/4187305/">Andrew Wayne Teesdale Jr.</a>
(<a href="/recipes/tags/ascii/">ascii</a>, <a href="/recipes/tags/text_anamation/">text_anamation</a>).
Revision 2.
</p>
<p>module to anamate text using a simple hack
def clear():
print "\n"*1000</p>
small stack language (Python)
2013-07-22T23:53:44-07:00Andrew Wayne Teesdale Jr.http://code.activestate.com/recipes/users/4187305/http://code.activestate.com/recipes/578617-small-stack-language/
<p style="color: grey">
Python
recipe 578617
by <a href="/recipes/users/4187305/">Andrew Wayne Teesdale Jr.</a>
(<a href="/recipes/tags/language/">language</a>, <a href="/recipes/tags/stack/">stack</a>).
</p>
<p>a small language in python</p>