Popular recipes tagged "meta:loc=122"http://code.activestate.com/recipes/tags/meta:loc=122/2015-12-01T16:23:09-08:00ActiveState Code RecipesHow to use super() effectively -- Python 3.2 version (Python)
2015-12-01T16:23:09-08:00Lance E Sloanhttp://code.activestate.com/recipes/users/4188012/http://code.activestate.com/recipes/579130-how-to-use-super-effectively-python-32-version/
<p style="color: grey">
Python
recipe 579130
by <a href="/recipes/users/4188012/">Lance E Sloan</a>
(<a href="/recipes/tags/cooperative/">cooperative</a>, <a href="/recipes/tags/inheritance/">inheritance</a>, <a href="/recipes/tags/multiple/">multiple</a>, <a href="/recipes/tags/next_in_mro/">next_in_mro</a>, <a href="/recipes/tags/super/">super</a>).
</p>
<p>Python's super() provides a unique and amazing capability. It allows subclasses to be written to reorder a chain method calls. The recipe demonstrates all of the tradecraft needed to get super() to do your bidding.</p>
How to use super() effectively -- Python 2.7 version (Python)
2015-12-01T16:20:26-08:00Lance E Sloanhttp://code.activestate.com/recipes/users/4188012/http://code.activestate.com/recipes/579129-how-to-use-super-effectively-python-27-version/
<p style="color: grey">
Python
recipe 579129
by <a href="/recipes/users/4188012/">Lance E Sloan</a>
(<a href="/recipes/tags/cooperative/">cooperative</a>, <a href="/recipes/tags/inheritance/">inheritance</a>, <a href="/recipes/tags/multiple/">multiple</a>, <a href="/recipes/tags/next_in_mro/">next_in_mro</a>, <a href="/recipes/tags/super/">super</a>).
</p>
<p>Python's super() provides a unique and amazing capability. It allows subclasses to be written to reorder a chain method calls. The recipe demonstrates all of the tradecraft needed to get super() to do your bidding.</p>
How to use super() effectively -- Python 2.7 version (Python)
2011-06-01T19:19:37-07:00Raymond Hettingerhttp://code.activestate.com/recipes/users/178123/http://code.activestate.com/recipes/577721-how-to-use-super-effectively-python-27-version/
<p style="color: grey">
Python
recipe 577721
by <a href="/recipes/users/178123/">Raymond Hettinger</a>
(<a href="/recipes/tags/cooperative/">cooperative</a>, <a href="/recipes/tags/inheritance/">inheritance</a>, <a href="/recipes/tags/multiple/">multiple</a>, <a href="/recipes/tags/next_in_mro/">next_in_mro</a>, <a href="/recipes/tags/super/">super</a>).
Revision 8.
</p>
<p>Python's super() provides a unique and amazing capability. It allows subclasses to be written to reorder a chain method calls. The recipe demonstrates all of the tradecraft needed to get super() to do your bidding.</p>
Locate and see the biggest cross in a random matrix (Python)
2013-09-13T13:31:03-07:00alexander bakerhttp://code.activestate.com/recipes/users/4166679/http://code.activestate.com/recipes/578657-locate-and-see-the-biggest-cross-in-a-random-matri/
<p style="color: grey">
Python
recipe 578657
by <a href="/recipes/users/4166679/">alexander baker</a>
(<a href="/recipes/tags/numpy/">numpy</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/search/">search</a>).
</p>
<p>Interesting search space problem.</p>
How to use super() effectively (Python)
2011-06-01T19:17:58-07:00Raymond Hettingerhttp://code.activestate.com/recipes/users/178123/http://code.activestate.com/recipes/577720-how-to-use-super-effectively/
<p style="color: grey">
Python
recipe 577720
by <a href="/recipes/users/178123/">Raymond Hettinger</a>
(<a href="/recipes/tags/cooperative/">cooperative</a>, <a href="/recipes/tags/inheritance/">inheritance</a>, <a href="/recipes/tags/multiple/">multiple</a>, <a href="/recipes/tags/next_in_mro/">next_in_mro</a>, <a href="/recipes/tags/super/">super</a>).
Revision 8.
</p>
<p>Python's super() provides a unique and amazing capability. It allows subclasses to be written to reorder a chain method calls. The recipe demonstrates all of the tradecraft needed to get super() to do your bidding.</p>
Dynamic Class Construction a la DSLs (Python)
2011-08-13T04:00:46-07:00Eric Snowhttp://code.activestate.com/recipes/users/4177816/http://code.activestate.com/recipes/577718-dynamic-class-construction-a-la-dsls/
<p style="color: grey">
Python
recipe 577718
by <a href="/recipes/users/4177816/">Eric Snow</a>
(<a href="/recipes/tags/collections/">collections</a>).
</p>
<p>So maybe it's not quite a mutable namedtuple. However, I borrowed heavily against the namedtuple implementation for this one.</p>
<p>I wanted to have a collection of classes that described data types without any functionality on them, sort of state holders. However, I wanted to use defaults and I wanted it to be mutable. </p>
<p>I noticed, as I started building my classes, that each was following the same pattern, so I extracted it out into this recipe. Wrapping namedtuple to get the same result would probably be feasible, but I enjoyed doing this too.</p>
<p>The distinction between parameters and properties is mostly one I was maintaining between single objects and collections. Realistically everything could have been parameters.</p>
peek ahead an iterator (Python)
2010-08-17T13:41:41-07:00Quintijn Hoogenboomhttp://code.activestate.com/recipes/users/4171692/http://code.activestate.com/recipes/577361-peek-ahead-an-iterator/
<p style="color: grey">
Python
recipe 577361
by <a href="/recipes/users/4171692/">Quintijn Hoogenboom</a>
(<a href="/recipes/tags/iter/">iter</a>, <a href="/recipes/tags/iterator/">iterator</a>, <a href="/recipes/tags/peek/">peek</a>, <a href="/recipes/tags/peeking/">peeking</a>).
</p>
<p>a merge of recipes 16.7 and 19.18 of the python cookbook (2nd edition).</p>
<p>you can peek ahead more steps if needed, or just use the preview variable for the next item of the list.</p>
Decoupled Proxy of a State Bearing Object in a Multiprocessing Environment (Python)
2010-04-08T04:36:05-07:00Mateyuzohttp://code.activestate.com/recipes/users/4172453/http://code.activestate.com/recipes/577180-decoupled-proxy-of-a-state-bearing-object-in-a-mul/
<p style="color: grey">
Python
recipe 577180
by <a href="/recipes/users/4172453/">Mateyuzo</a>
(<a href="/recipes/tags/access/">access</a>, <a href="/recipes/tags/multiprocessing/">multiprocessing</a>, <a href="/recipes/tags/process/">process</a>, <a href="/recipes/tags/processing/">processing</a>, <a href="/recipes/tags/subprocess/">subprocess</a>, <a href="/recipes/tags/synchronization/">synchronization</a>, <a href="/recipes/tags/syncmanager/">syncmanager</a>, <a href="/recipes/tags/threading/">threading</a>, <a href="/recipes/tags/__getattribute__/">__getattribute__</a>).
Revision 2.
</p>
<p>Describes a simple example of the potential for shared Singleton or Borg object methods to be proxy'd by an object that SyncManger can present to requesting subprocesses.</p>
argdeclare: declarative interface to argparse (Python)
2010-03-02T00:05:40-08:00Shakeeb Alirezahttp://code.activestate.com/recipes/users/4172101/http://code.activestate.com/recipes/576935-argdeclare-declarative-interface-to-argparse/
<p style="color: grey">
Python
recipe 576935
by <a href="/recipes/users/4172101/">Shakeeb Alireza</a>
(<a href="/recipes/tags/argparse/">argparse</a>, <a href="/recipes/tags/cmdln/">cmdln</a>, <a href="/recipes/tags/commandline/">commandline</a>, <a href="/recipes/tags/getopt/">getopt</a>, <a href="/recipes/tags/metaclass/">metaclass</a>, <a href="/recipes/tags/option/">option</a>).
Revision 5.
</p>
<p>This is an implementation of the interface provided by the <a href="http://code.google.com/p/cmdln/">cmdln</a> module but using <a href="http://code.google.com/p/argparse/">argparse</a> to provide the option/arg heavy parsing.</p>
<p>An example of usage is provided in the <code>test</code> function, which should produce the following from the command line:</p>
<p>$ python argdeclare.py --help</p>
<pre class="prettyprint"><code>usage: argdeclare.py [-h] [-v] {uninstall,install,delete} ...
a description of the test app
optional arguments:
-h, --help show this help message and exit
-v, --version show program's version number and exit
subcommands:
valid subcommands
{uninstall,install,delete}
additional help
delete help text for delete subcmd
install help text for install subcmd
uninstall help text for uninstall subcmd
</code></pre>
<p>$ python argdeclare.py install --help</p>
<pre class="prettyprint"><code>usage: argdeclare.py install [-h] [-t TYPE] [--log] [-f] package
positional arguments:
package package to be (un)installed
optional arguments:
-h, --help show this help message and exit
-t TYPE, --type TYPE specify type of package
--log, -l log is on
-f, --force force through installation
</code></pre>
<p>enjoy!</p>
<p>SA</p>
Simple MultiThreaded Timer Job Controller (Python)
2009-05-11T02:05:16-07:00sumerchttp://code.activestate.com/recipes/users/4170198/http://code.activestate.com/recipes/576748-simple-multithreaded-timer-job-controller/
<p style="color: grey">
Python
recipe 576748
by <a href="/recipes/users/4170198/">sumerc</a>
(<a href="/recipes/tags/job/">job</a>, <a href="/recipes/tags/multithread/">multithread</a>, <a href="/recipes/tags/task/">task</a>, <a href="/recipes/tags/timer/">timer</a>).
Revision 2.
</p>
<p>We have tried to write an audit for our server to check our server's connection, status and other internal info and there are multiple threads invoking multiple tasks. So I came up with this simple utility that takes a job and runs it in a specific interval.</p>
Evolution optimization strategy (Python)
2009-04-20T06:31:13-07:00Agnius Vasiliauskashttp://code.activestate.com/recipes/users/4169134/http://code.activestate.com/recipes/576645-evolution-optimization-strategy/
<p style="color: grey">
Python
recipe 576645
by <a href="/recipes/users/4169134/">Agnius Vasiliauskas</a>
(<a href="/recipes/tags/ai/">ai</a>, <a href="/recipes/tags/evolution/">evolution</a>, <a href="/recipes/tags/evolution_strategy/">evolution_strategy</a>, <a href="/recipes/tags/gene/">gene</a>, <a href="/recipes/tags/genetic_algorithm/">genetic_algorithm</a>, <a href="/recipes/tags/np_complete/">np_complete</a>, <a href="/recipes/tags/optimization/">optimization</a>).
Revision 6.
</p>
<p>Algorithm for solving search and optimization problems.</p>
A native implementation of threading.Lock and threading.RLock using Pyrex (Python)
2004-10-19T13:37:44-07:00Nicolas Lehuenhttp://code.activestate.com/recipes/users/1599156/http://code.activestate.com/recipes/310792-a-native-implementation-of-threadinglock-and-threa/
<p style="color: grey">
Python
recipe 310792
by <a href="/recipes/users/1599156/">Nicolas Lehuen</a>
(<a href="/recipes/tags/threads/">threads</a>).
</p>
<p>Locks or mutexes are very basic primitives used to coordinate threads operations in multi-threaded programs. Unfortunately, even if Python provides a low-level implementation of locks in the thread module, the high level implementation of threading RLock is still in Python code, which is a bit worrying since locking is always a time critical task. This recipe implements both locks in Pyrex to get the speed of native code, and gives an example of how great Pyrex is.</p>
Extending ConfigParser for reading and writing options from Windows Registry (Python)
2002-07-11T02:48:41-07:00Ivan Begtinhttp://code.activestate.com/recipes/users/124002/http://code.activestate.com/recipes/138944-extending-configparser-for-reading-and-writing-opt/
<p style="color: grey">
Python
recipe 138944
by <a href="/recipes/users/124002/">Ivan Begtin</a>
(<a href="/recipes/tags/ui/">ui</a>).
</p>
<p>This class extends ConfigParser class to make it able to read and write configuration settings from specified registry key.
Code below should work with ActivePython 2.1+</p>