Popular recipes tagged "meta:loc=121"http://code.activestate.com/recipes/tags/meta:loc=121/2015-04-16T12:11:34-07:00ActiveState Code RecipesHashing Nonhashable / Mutable Objects (Python) 2015-04-16T12:11:34-07:00Max Morozhttp://code.activestate.com/recipes/users/4168744/http://code.activestate.com/recipes/579047-hashing-nonhashable-mutable-objects/ <p style="color: grey"> Python recipe 579047 by <a href="/recipes/users/4168744/">Max Moroz</a> (<a href="/recipes/tags/hash/">hash</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/python3/">python3</a>). Revision 2. </p> <p>This class is intended as a wrapper for non-hashable objects (such as lists, dictionaries, etc.) in situations where the object is known to be immutable. Example: memoization of function arguments.</p> <p>Feedback much appreciated, I will update to reflect any comments.</p> Hex2Dec (Batch) 2013-02-21T13:25:23-08:00greg zakharovhttp://code.activestate.com/recipes/users/4184115/http://code.activestate.com/recipes/578309-hex2dec/ <p style="color: grey"> Batch recipe 578309 by <a href="/recipes/users/4184115/">greg zakharov</a> (<a href="/recipes/tags/hex2dec/">hex2dec</a>). Revision 7. </p> <p>Many must be familiar with the excellent utility by Mark Russinovich called hex2dec. It is good to all, but I would like to add interactivity to it. So I wrote a "clone" on command language.</p> Indexable Generator (Python) 2012-01-03T06:10:18-08:00Peter Donishttp://code.activestate.com/recipes/users/4180313/http://code.activestate.com/recipes/578000-indexable-generator/ <p style="color: grey"> Python recipe 578000 by <a href="/recipes/users/4180313/">Peter Donis</a> (<a href="/recipes/tags/decorators/">decorators</a>, <a href="/recipes/tags/generators/">generators</a>). Revision 4. </p> <p>A decorator for generators that makes them indexable like a sequence.</p> Hanoi Towers solver wxPython (Python) 2010-12-21T21:11:33-08:00A. Polinohttp://code.activestate.com/recipes/users/4176317/http://code.activestate.com/recipes/577511-hanoi-towers-solver-wxpython/ <p style="color: grey"> Python recipe 577511 by <a href="/recipes/users/4176317/">A. Polino</a> (<a href="/recipes/tags/hanoi/">hanoi</a>, <a href="/recipes/tags/problem/">problem</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/solver/">solver</a>, <a href="/recipes/tags/wx/">wx</a>). Revision 3. </p> <p>It's a simple solver of the problem of Hanoi Tower with a minimal GUI written in wxPython. It can handle just 10 plates, due to windows size..however it's very simple to modify this and the 'pure' solver is not affected by this limitation</p> Private attributes in CPython (Python) 2008-06-05T04:40:14-07:00Carl Bankshttp://code.activestate.com/recipes/users/686106/http://code.activestate.com/recipes/573442-private-attributes-in-cpython/ <p style="color: grey"> Python recipe 573442 by <a href="/recipes/users/686106/">Carl Banks</a> (<a href="/recipes/tags/oop/">oop</a>). </p> <p>Metaclass that allows for private attributes. Classes can ensure privacy of their data by checking the stack frame inside __setattr__ and __getattribute__ to see if the function requesting the attribute was defined as part of the class.</p> Automated swigging for creating simple C shared modules. (Python) 2006-04-25T10:22:46-07:00Ernesto Adoriohttp://code.activestate.com/recipes/users/2765793/http://code.activestate.com/recipes/491290-automated-swigging-for-creating-simple-c-shared-mo/ <p style="color: grey"> Python recipe 491290 by <a href="/recipes/users/2765793/">Ernesto Adorio</a> (<a href="/recipes/tags/extending/">extending</a>). Revision 2. </p> <p>A simple python function to automate using the swig process for creating C modules for use inside Python.</p> disk.py (Python) 2006-04-26T09:37:05-07:00Stephen Chappellhttp://code.activestate.com/recipes/users/2608421/http://code.activestate.com/recipes/492208-diskpy/ <p style="color: grey"> Python recipe 492208 by <a href="/recipes/users/2608421/">Stephen Chappell</a> (<a href="/recipes/tags/files/">files</a>). </p> <p>The following recipe provides a simple simulation of secondary memory and is primarily designed to provide a driver interface to a virtual hard drive. The interface is simple and allows the simulation of IO errors. Also provided are methods that allow efficient storage are retrieval of a disk object on the computer's file system.</p> mthread.py (version 2) (Python) 2006-01-25T00:28:44-08:00Stephen Chappellhttp://code.activestate.com/recipes/users/2608421/http://code.activestate.com/recipes/473781-mthreadpy-version-2/ <p style="color: grey"> Python recipe 473781 by <a href="/recipes/users/2608421/">Stephen Chappell</a> (<a href="/recipes/tags/threads/">threads</a>). Revision 2. </p> <p>This program demonstrates code ported from C to Python. 1. The port is not very pythonic (see the first version for that). 2. The port is almost a straight line-by-line translation of code. 3. The code came from OPERATING SYSTEMS: Third Edition (by GARY NUTT). 4. The code involves LAB EXERCISE 2.2 (on pages 83 -- 88).</p> Making telephone calls from your python program using Voicent Gateway (Python) 2005-10-13T16:28:19-07:00Andrew Kernhttp://code.activestate.com/recipes/users/2626663/http://code.activestate.com/recipes/441239-making-telephone-calls-from-your-python-program-us/ <p style="color: grey"> Python recipe 441239 by <a href="/recipes/users/2626663/">Andrew Kern</a> (<a href="/recipes/tags/programs/">programs</a>). </p> <p>The Voicent Python Simple Interface class contains the following functions.</p> <pre class="prettyprint"><code>callText callAudio callStatus callRemove callTillConfirm </code></pre> <p>These functions are used to invoke telephone calls from your Python program. For example, callText is used to call a specified number and automatically play your text message using text-to-speech engine.</p> <p>In order for this class to work, you'll need to have Voicent Gateway installed somewhere in your network. This class simply sends HTTP request for telephone calls to the gateway. Voicent has a free edition for the gateway. You can download it from <a href="http://www.voicent.com" rel="nofollow">http://www.voicent.com</a></p> <p>More information can be found at: <a href="http://www.voicent.com/devnet/docs/pyapi.htm" rel="nofollow">http://www.voicent.com/devnet/docs/pyapi.htm</a></p> Memory compacted list of bits (Python) 2005-10-10T02:08:35-07:00Connelly Barneshttp://code.activestate.com/recipes/users/1859269/http://code.activestate.com/recipes/440658-memory-compacted-list-of-bits/ <p style="color: grey"> Python recipe 440658 by <a href="/recipes/users/1859269/">Connelly Barnes</a> . Revision 5. </p> <p>A list of bits, compacted in memory so that 8 elements use 1 byte of storage.</p> webcounter (Python) 2004-10-15T05:33:47-07:00Michael Foordhttp://code.activestate.com/recipes/users/1565518/http://code.activestate.com/recipes/310320-webcounter/ <p style="color: grey"> Python recipe 310320 by <a href="/recipes/users/1565518/">Michael Foord</a> (<a href="/recipes/tags/cgi/">cgi</a>). </p> <p>This CGI will generate a simple text 'hit counter' for several sites. Useful to ocunt visitors to the 'front door' of your website.</p> Colorize Python source using the built-in tokenizer (Python) 2001-04-06T23:05:53-07:00Jürgen Hermannhttp://code.activestate.com/recipes/users/98061/http://code.activestate.com/recipes/52298-colorize-python-source-using-the-built-in-tokenize/ <p style="color: grey"> Python recipe 52298 by <a href="/recipes/users/98061/">Jürgen Hermann</a> (<a href="/recipes/tags/programs/">programs</a>). Revision 3. </p> <p>This code is part of MoinMoin (<a href="http://moin.sourceforge.net/" rel="nofollow">http://moin.sourceforge.net/</a>) and converts Python source code to HTML markup, rendering comments, keywords, operators, numeric and string literals in different colors.</p> <p>It shows how to use the built-in keyword, token and tokenize modules to scan Python source code and re-emit it with no changes to its original formatting (which is the hard part).</p> <p>The test code at the bottom of the module formats itself and launches a browser with the result.</p> VW.TCL -- TK Text File Viewer (Tcl) 2001-09-10T23:35:17-07:00Tony Dyckshttp://code.activestate.com/recipes/users/115142/http://code.activestate.com/recipes/68395-vwtcl-tk-text-file-viewer/ <p style="color: grey"> Tcl recipe 68395 by <a href="/recipes/users/115142/">Tony Dycks</a> (<a href="/recipes/tags/binding/">binding</a>). </p> <p>A Text File Viewer Program Utilizing a Text Widget With A Vertical Scrollbar. Menu And Button Widgets Are Used In Conjunction With a tk_getOpenFile Dialog Window To Allow The User To Select A Text File For Viewing. A Menu Option And Button Widget Enable A Program Exit Option.</p>