Popular recipes tagged "meta:requires=exceptions" but not "ssh" and "postgres"http://code.activestate.com/recipes/tags/meta:requires=exceptions-ssh-postgres/popular/2010-03-13T11:53:18-08:00ActiveState Code RecipesObserver pattern implemented with Descriptor class (Python)
2010-03-13T11:53:18-08:00Rodney Drenthhttp://code.activestate.com/recipes/users/4050661/http://code.activestate.com/recipes/576979-observer-pattern-implemented-with-descriptor-class/
<p style="color: grey">
Python
recipe 576979
by <a href="/recipes/users/4050661/">Rodney Drenth</a>
(<a href="/recipes/tags/descriptor/">descriptor</a>, <a href="/recipes/tags/observer/">observer</a>, <a href="/recipes/tags/publish/">publish</a>, <a href="/recipes/tags/subscribe/">subscribe</a>).
Revision 5.
</p>
<p>The observer pattern is implemented using an observable descriptor.
One creates instances of observable in a class, which allows observers to
subscribe to changes in the observable. Assigning a value to the observable
causes the suscribers to be notified. An observable can subscribe to another observable, in which case changes to the second propagate to subscribers of the first.
The subscribe method returns a Subscription object. When this object is deleted or becomes unreferenced, the subscription is cancelled.</p>
Global Signal Dispatching (Python)
2001-12-11T19:30:28-08:00Patrick O'Brienhttp://code.activestate.com/recipes/users/137858/http://code.activestate.com/recipes/87056-global-signal-dispatching/
<p style="color: grey">
Python
recipe 87056
by <a href="/recipes/users/137858/">Patrick O'Brien</a>
.
Revision 4.
</p>
<p>This module, dispatcher.py, provides global signal dispatching services suitable for a wide variety of purposes, similar to Model-View-Controller or Model-View-Presenter patterns. This particular implementation allows a looser coupling than most Observer patterns. It also does transparent cleanup through the use of weak references and weak reference callbacks. This version defaults to using weak references, but provides an option to not use weak references for those cases where weak references are problematic (lambdas and such).</p>
Enums for Python (Python)
2001-08-23T14:57:17-07:00Will Warehttp://code.activestate.com/recipes/users/98156/http://code.activestate.com/recipes/67107-enums-for-python/
<p style="color: grey">
Python
recipe 67107
by <a href="/recipes/users/98156/">Will Ware</a>
(<a href="/recipes/tags/programs/">programs</a>).
</p>
<p>I once tried to give Python something like C's enums, as described
here: <a href="http://groups.google.com/groups?selm=G6qzLy.6Fo%2540world.std.com" rel="nofollow">http://groups.google.com/groups?selm=G6qzLy.6Fo%40world.std.com</a>
That approach tried to assign to a dictionary returned by the locals()
function, intending that such assignments would become class attributes.
The Tim-bot explained to me the errors of my ways. The quest for the
perfect Python enum goes on.</p>
A Dictionary-based two-dimensional ragged array. (Python)
2001-10-03T04:40:03-07:00Peter Olsenhttp://code.activestate.com/recipes/users/132220/http://code.activestate.com/recipes/68430-a-dictionary-based-two-dimensional-ragged-array/
<p style="color: grey">
Python
recipe 68430
by <a href="/recipes/users/132220/">Peter Olsen</a>
.
Revision 2.
</p>
<p>This class implements a two-dimensional ragged array using nested dictionaries.</p>
<p>As written this class requires Python 2.2 or later. This meets my requirements, but it may not
meet yours.</p>
<p>Klaus Alexander Seistrup has described a way to get around this restriction by substituting
"UserDict.UserDict" for "dictionary" as the base class. I believe this solves the problem
for Python versions at least as far back as 1.5.2. This approach will require some editing of
the insertion and retrieval functions to make it work.</p>
<p>Thanks Klaus!</p>
Latitude/longitude/map web-fetcher (Python)
2001-08-20T18:11:28-07:00Will Warehttp://code.activestate.com/recipes/users/98156/http://code.activestate.com/recipes/52548-latitudelongitudemap-web-fetcher/
<p style="color: grey">
Python
recipe 52548
by <a href="/recipes/users/98156/">Will Ware</a>
(<a href="/recipes/tags/web/">web</a>).
Revision 2.
</p>
<p>Given a list of cities, this recipe fetches their latitudes and longitudes from
one website (a database used for astrology, of all things) and uses them to
build a URL for another website which creates a map highlighting the cities
against the outlines of continents. Maybe some day it will be clever enough to
load the latitudes and longitudes as waypoints into your GPS receiver.</p>