<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel>
<title>Snipplr</title>
<link>http://snipplr.com/language/python</link>
<description>Recent snippets posted on Snipplr.com</description>
<language>en-us</language>
<pubDate>Sun, 06 Jul 2008 21:22:38 GMT</pubDate>
<item>
<title>(Python) Name Mangling of Python Private Variables - ishikawa</title>
<link>http://snipplr.com/view/7027/name-mangling-of-python-private-variables/</link>
<description><![CDATA[ <p>Python: Private Variables
http://docs.python.org/tut/node11.html#SECTION0011600000000000000000

Any identifier of the form __spam (at least two leading underscores, at most one trailing underscore) is textually replaced with _classname__spam, where classname is the current class name with leading underscore(s) stripped.

Truncation may occur when the mangled name would be longer than 255 characters. When the class name consists of only underscores, no mangling occurs.</p> ]]></description>
<pubDate>Mon, 30 Jun 2008 10:08:15 GMT</pubDate>
<guid>http://snipplr.com/view/7027/name-mangling-of-python-private-variables/</guid>
</item>
<item>
<title>(Python) Sieve of Eratostenes - Kartoffel</title>
<link>http://snipplr.com/view/7014/sieve-of-eratostenes/</link>
<description><![CDATA[ <p>An (probably inefficient) implementation of the Sieve of Eratostenes. The function returns a list containing all the prime numbers between 0 and the number passed to it.</p> ]]></description>
<pubDate>Sun, 29 Jun 2008 12:58:00 GMT</pubDate>
<guid>http://snipplr.com/view/7014/sieve-of-eratostenes/</guid>
</item>
<item>
<title>(Python) Unit tests with Python - chombee</title>
<link>http://snipplr.com/view/6739/unit-tests-with-python/</link>
<description><![CDATA[ <p>Test-first programming, in which you write the unit tests first with the unittest module and then work on the code until it passes all the tests, seems like a good substitute for writing interfaces or documentation first. The unit tests are like an API, describing the interface of the code being tested. And they lend themselves well to refactoring.

This is a first attempt at a unit test for the messager.py module posted earlier.</p> ]]></description>
<pubDate>Mon, 16 Jun 2008 10:35:25 GMT</pubDate>
<guid>http://snipplr.com/view/6739/unit-tests-with-python/</guid>
</item>
<item>
<title>(Python) Messager pattern from Panda3D - chombee</title>
<link>http://snipplr.com/view/6650/messager-pattern-from-panda3d/</link>
<description><![CDATA[ <p>This is my implementation of the messager pattern used by Panda3D for event
handling. It's a really nice idea but I think Panda's version is implemented
weirdly, it uses the subscribe objects as keys in the dictionary. That means
that if you want more than one object to subscribe to the same message you
_have_ to subclass DirectObject and use self.accept(...), can't just call the
messager directly or you'll get a different behaviour, it means that a single
object instance can't subscribe two different functions to the same message, and
it means that your _objects_ have to be _hashable_ (!) because the messager uses
them as keys in a dictionary. It seems to me that it would be much simpler if
the messager's dictionary just mapped message names to function objects, so
that's what I did.

Use this pattern when you have a lot of objects spread throughout the class
hierarchy that need to communicate with each other. It's a way of implementing
one-to-many or many-to-many communication, in which an object can send a message
to many receivers without needing to know who those receivers are, or how many
receivers there are, or even if there are any receivers (although an object can
potentially check all these things if it wants to). The singleton messager
object receives messages from broadcaster objects and forwards them to receiver
objects. Setup a single, simple, generic, system- wide messaging system, instead
of creating different systems for each different type of message or messaging
relation.

The disadvantage of just implementing this pattern once and using it everywhere
is that with lots of senders and receivers it might become difficult to
understand and debug message-based behaviour. Particularly if the order in which
messages are sent and received becomes important, when you send a message with
this pattern there's no way of knowing in what order the receiver objects will
receive the message, and therefore know way of knowing in what order their
responses will be executed, and those responses may include sending more
messages. You can implement some ordering relations by having an object receive
a message, deal with it, then send a different message to other recievers, but I
wouldn't want to overuse that.

Also you have to be careful to avoid clashes in message names.

The GoF Mediator and Observer patterns are similar in that they enable a mode 
of communication between objects in which the sender object broadcasts a 
message without needing to know all of the receiver objects, and the receiver 
objects can receive messages without being tightly coupled to the sender 
object(s).

In the GoF Mediator pattern, the Mediator object is more than just a messager 
that passes messages between other objects and leaves the behaviour up to the 
others. The mediator actually encapsulates the interaction behaviour between 
objects, deciding which methods to call on which objects each time it receives 
a notification from an object. Mediator centralises control of how objects 
cooperate in the mediator class, whereas the Messager pattern leaves this 
control distributed throughout the objects themselves.

In the GoF observer pattern a one-to-many dependency is setup, there is no 
separate Messager object but rather the sender object itself maintains the list 
of reciever object and notifies them of new messages. With its separate 
messager object the Messager pattern enables many-to-many dependencies as well 
as one-to-many.</p> ]]></description>
<pubDate>Wed, 11 Jun 2008 07:03:17 GMT</pubDate>
<guid>http://snipplr.com/view/6650/messager-pattern-from-panda3d/</guid>
</item>
<item>
<title>(Python) Reading and writing text files in Python - chombee</title>
<link>http://snipplr.com/view/6630/reading-and-writing-text-files-in-python/</link>
<description><![CDATA[ <p></p> ]]></description>
<pubDate>Mon, 09 Jun 2008 09:48:40 GMT</pubDate>
<guid>http://snipplr.com/view/6630/reading-and-writing-text-files-in-python/</guid>
</item>
<item>
<title>(Python) Creating list-like objects in Python - chombee</title>
<link>http://snipplr.com/view/6626/creating-listlike-objects-in-python/</link>
<description><![CDATA[ <p></p> ]]></description>
<pubDate>Sun, 08 Jun 2008 18:34:00 GMT</pubDate>
<guid>http://snipplr.com/view/6626/creating-listlike-objects-in-python/</guid>
</item>
<item>
<title>(Python) Creating dictionary-like objects in Python using DictMixin - chombee</title>
<link>http://snipplr.com/view/6546/creating-dictionarylike-objects-in-python-using-dictmixin/</link>
<description><![CDATA[ <p></p> ]]></description>
<pubDate>Mon, 02 Jun 2008 11:45:35 GMT</pubDate>
<guid>http://snipplr.com/view/6546/creating-dictionarylike-objects-in-python-using-dictmixin/</guid>
</item>
<item>
<title>(Python) Adding and removing collide masks - chombee</title>
<link>http://snipplr.com/view/6505/adding-and-removing-collide-masks/</link>
<description><![CDATA[ <p></p> ]]></description>
<pubDate>Fri, 30 May 2008 12:20:55 GMT</pubDate>
<guid>http://snipplr.com/view/6505/adding-and-removing-collide-masks/</guid>
</item>
<item>
<title>(Python) Panda3D's BitMask32 class (collision masks) - chombee</title>
<link>http://snipplr.com/view/6504/panda3ds-bitmask32-class-collision-masks/</link>
<description><![CDATA[ <p></p> ]]></description>
<pubDate>Fri, 30 May 2008 11:35:29 GMT</pubDate>
<guid>http://snipplr.com/view/6504/panda3ds-bitmask32-class-collision-masks/</guid>
</item>
<item>
<title>(Python) Hello World - erl</title>
<link>http://snipplr.com/view/6493/hello-world/</link>
<description><![CDATA[ <p></p> ]]></description>
<pubDate>Thu, 29 May 2008 12:05:33 GMT</pubDate>
<guid>http://snipplr.com/view/6493/hello-world/</guid>
</item>
<item>
<title>(Python) Código a tocar para usar twisted desde un servicio de red en windows - buscarini</title>
<link>http://snipplr.com/view/6468/cdigo-a-tocar-para-usar-twisted-desde-un-servicio-de-red-en-windows/</link>
<description><![CDATA[ <p>Al intentar importar reactor windows da un error de acceso denegado.</p> ]]></description>
<pubDate>Tue, 27 May 2008 05:38:20 GMT</pubDate>
<guid>http://snipplr.com/view/6468/cdigo-a-tocar-para-usar-twisted-desde-un-servicio-de-red-en-windows/</guid>
</item>
<item>
<title>(Python) get memory usage of current process on unix - fnl</title>
<link>http://snipplr.com/view/6460/get-memory-usage-of-current-process-on-unix/</link>
<description><![CDATA[ <p></p> ]]></description>
<pubDate>Mon, 26 May 2008 23:03:02 GMT</pubDate>
<guid>http://snipplr.com/view/6460/get-memory-usage-of-current-process-on-unix/</guid>
</item>
<item>
<title>(Python) YouTube Batch Download Script - abhiomkar</title>
<link>http://snipplr.com/view/6451/youtube-batch-download-script/</link>
<description><![CDATA[ <p>You</p> ]]></description>
<pubDate>Sun, 25 May 2008 14:02:29 GMT</pubDate>
<guid>http://snipplr.com/view/6451/youtube-batch-download-script/</guid>
</item>
<item>
<title>(Python) iterates over the bytes of string - ishikawa</title>
<link>http://snipplr.com/view/6254/iterates-over-the-bytes-of-string/</link>
<description><![CDATA[ <p></p> ]]></description>
<pubDate>Thu, 15 May 2008 23:41:29 GMT</pubDate>
<guid>http://snipplr.com/view/6254/iterates-over-the-bytes-of-string/</guid>
</item>
<item>
<title>(Python) read a big5 file and print to stdout in utf8 - ckyang74</title>
<link>http://snipplr.com/view/6250/read-a-big5-file-and-print-to-stdout-in-utf8/</link>
<description><![CDATA[ <p></p> ]]></description>
<pubDate>Thu, 15 May 2008 18:55:14 GMT</pubDate>
<guid>http://snipplr.com/view/6250/read-a-big5-file-and-print-to-stdout-in-utf8/</guid>
</item>
<item>
<title>(Python) Recursively find subversion working copies and update - claytron</title>
<link>http://snipplr.com/view/6228/recursively-find-subversion-working-copies-and-update/</link>
<description><![CDATA[ <p>Little utility script I wrote to find subversion working copies and update them.  If no arguments are given the script starts from the current directory.</p> ]]></description>
<pubDate>Thu, 15 May 2008 01:05:05 GMT</pubDate>
<guid>http://snipplr.com/view/6228/recursively-find-subversion-working-copies-and-update/</guid>
</item>
<item>
<title>(Python) Python Regular Expression Cheat Sheet - qrist0ph</title>
<link>http://snipplr.com/view/6206/python-regular-expression-cheat-sheet/</link>
<description><![CDATA[ <p></p> ]]></description>
<pubDate>Tue, 13 May 2008 07:57:58 GMT</pubDate>
<guid>http://snipplr.com/view/6206/python-regular-expression-cheat-sheet/</guid>
</item>
<item>
<title>(Python) Format Date - qrist0ph</title>
<link>http://snipplr.com/view/6204/format-date/</link>
<description><![CDATA[ <p></p> ]]></description>
<pubDate>Tue, 13 May 2008 06:21:11 GMT</pubDate>
<guid>http://snipplr.com/view/6204/format-date/</guid>
</item>
<item>
<title>(Python) Run Shell Command - qrist0ph</title>
<link>http://snipplr.com/view/6203/run-shell-command/</link>
<description><![CDATA[ <p></p> ]]></description>
<pubDate>Tue, 13 May 2008 06:12:28 GMT</pubDate>
<guid>http://snipplr.com/view/6203/run-shell-command/</guid>
</item>
<item>
<title>(Python) Python Filesystem Cheat Sheet - qrist0ph</title>
<link>http://snipplr.com/view/6202/python-filesystem-cheat-sheet/</link>
<description><![CDATA[ <p></p> ]]></description>
<pubDate>Tue, 13 May 2008 06:11:29 GMT</pubDate>
<guid>http://snipplr.com/view/6202/python-filesystem-cheat-sheet/</guid>
</item>
</channel>
</rss>