<?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/tags/python</link>
<description>Recent snippets posted on Snipplr.com</description>
<language>en-us</language>
<pubDate>Fri, 04 Jul 2008 16:52:12 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) 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) 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) 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) Scrape twitterlocal and save to Django model - mandric</title>
<link>http://snipplr.com/view/6080/scrape-twitterlocal-and-save-to-django-model/</link>
<description><![CDATA[ <p>going to use twitterlocal to play around a bit with pygooglechart.</p> ]]></description>
<pubDate>Thu, 01 May 2008 17:20:58 GMT</pubDate>
<guid>http://snipplr.com/view/6080/scrape-twitterlocal-and-save-to-django-model/</guid>
</item>
<item>
<title>(PHP) Simple PHP ViewObject generator - donkawechico</title>
<link>http://snipplr.com/view/6033/simple-php-viewobject-generator/</link>
<description><![CDATA[ <p>Any time I make PHP applications that interact with a database, I use this script. It generates one or more self-populating "View Objects" (a class that represents a single record from a DB). For example, rather than access a MySQL record-set by array indices (e.g. $row[1]), you can populate an object with the record's values, and reference them like properties in an object (e.g. $productVO->price).

To use:
1. Create a ".vo" file. For example, if you have a Products table, make "products.vo". 
2. In this file, you will map column names to some string of your choice. This string will be used to name the getter/setter functions in the generated class. "get" and "set" will be pre-pended to these mapped names automatically, so don't include them. Like so:
[column 1 name]:[desired function name]
[column 2 name]:[desired function name] ...
e.g. 

file "product.vo":

id:Id
price:Price
desc:Description

This will generate a class with functions "getId()", "getPrice()", and "getDescription()", returning the appropriate attribute.
3. Edit the folder names in the python source below to match your setup
4. Run ./voGenerator.py -a

This will generate views for all ".vo" files in the directory specified in the python script as well as an "AllViews.php" file which, when included in your PHP code, imports all view files. View files take the form [filename]VO.php as in ProductVO.php

To populate these objects, use the following snippit:

function getAllProducts() {
		$products = array();
		$row = array();
		$result = query("SELECT * FROM products");

		while ($row = mysql_fetch_assoc($result)) {
			$pVO = new ProductsVO;
			$pVO->populate($row);
			array_push($products, $pVO);
		}

		return $products;
}</p> ]]></description>
<pubDate>Mon, 28 Apr 2008 18:54:13 GMT</pubDate>
<guid>http://snipplr.com/view/6033/simple-php-viewobject-generator/</guid>
</item>
<item>
<title>(Diff) Apple's modifications to Python 2.5.1 (locale.py, ...) - ishikawa</title>
<link>http://snipplr.com/view/6028/apples-modifications-to-python-251-localepy-/</link>
<description><![CDATA[ <p></p> ]]></description>
<pubDate>Mon, 28 Apr 2008 08:09:17 GMT</pubDate>
<guid>http://snipplr.com/view/6028/apples-modifications-to-python-251-localepy-/</guid>
</item>
<item>
<title>(Python) Posting to Twitter from Google AppEngine - sgraber</title>
<link>http://snipplr.com/view/5954/posting-to-twitter-from-google-appengine/</link>
<description><![CDATA[ <p>A way to post to twitter from Google AppEngine using urlfetch.</p> ]]></description>
<pubDate>Tue, 22 Apr 2008 09:48:26 GMT</pubDate>
<guid>http://snipplr.com/view/5954/posting-to-twitter-from-google-appengine/</guid>
</item>
<item>
<title>(Other) Django: dump SQL data into an xml file - wbowers</title>
<link>http://snipplr.com/view/5861/django-dump-sql-data-into-an-xml-file/</link>
<description><![CDATA[ <p></p> ]]></description>
<pubDate>Tue, 15 Apr 2008 04:45:03 GMT</pubDate>
<guid>http://snipplr.com/view/5861/django-dump-sql-data-into-an-xml-file/</guid>
</item>
<item>
<title>(Python) Python sleep - arcturus</title>
<link>http://snipplr.com/view/5763/python-sleep/</link>
<description><![CDATA[ <p></p> ]]></description>
<pubDate>Thu, 10 Apr 2008 04:14:03 GMT</pubDate>
<guid>http://snipplr.com/view/5763/python-sleep/</guid>
</item>
<item>
<title>(Python) Python: elapsed_time (human readable time span given total seconds) - wbowers</title>
<link>http://snipplr.com/view/5713/python-elapsedtime-human-readable-time-span-given-total-seconds/</link>
<description><![CDATA[ <p>This function takes an amount of time in seconds and returns a human readable time span (i.e.,  4h 5m 23s). The suffixes (d for day, h for hour) are configurable to whatever you want (like day, hour, week, etc). Read the comments within the code for more detail.</p> ]]></description>
<pubDate>Sat, 05 Apr 2008 17:35:31 GMT</pubDate>
<guid>http://snipplr.com/view/5713/python-elapsedtime-human-readable-time-span-given-total-seconds/</guid>
</item>
<item>
<title>(Python) New Python App Shell - kangell</title>
<link>http://snipplr.com/view/5535/new-python-app-shell/</link>
<description><![CDATA[ <p>Use this to start of new python applications.</p> ]]></description>
<pubDate>Sat, 22 Mar 2008 21:47:47 GMT</pubDate>
<guid>http://snipplr.com/view/5535/new-python-app-shell/</guid>
</item>
<item>
<title>(Python) Python console application template with logging and option parsing. - pulczynski</title>
<link>http://snipplr.com/view/5519/python-console-application-template-with-logging-and-option-parsing/</link>
<description><![CDATA[ <p></p> ]]></description>
<pubDate>Fri, 21 Mar 2008 08:07:21 GMT</pubDate>
<guid>http://snipplr.com/view/5519/python-console-application-template-with-logging-and-option-parsing/</guid>
</item>
<item>
<title>(Other) Fabric Plugin Diff - rob_cowie</title>
<link>http://snipplr.com/view/5340/fabric-plugin-diff/</link>
<description><![CDATA[ <p></p> ]]></description>
<pubDate>Sun, 09 Mar 2008 14:42:25 GMT</pubDate>
<guid>http://snipplr.com/view/5340/fabric-plugin-diff/</guid>
</item>
<item>
<title>(Python) GUI Collector - Validator Library - stagger</title>
<link>http://snipplr.com/view/5186/gui-collector--validator-library/</link>
<description><![CDATA[ <p></p> ]]></description>
<pubDate>Sun, 24 Feb 2008 23:02:21 GMT</pubDate>
<guid>http://snipplr.com/view/5186/gui-collector--validator-library/</guid>
</item>
<item>
<title>(Python) GUI Collector - SoftPRO Library - stagger</title>
<link>http://snipplr.com/view/5185/gui-collector--softpro-library/</link>
<description><![CDATA[ <p>This is the SoftPRO library needed by the GUI Collector main file.</p> ]]></description>
<pubDate>Sun, 24 Feb 2008 23:02:00 GMT</pubDate>
<guid>http://snipplr.com/view/5185/gui-collector--softpro-library/</guid>
</item>
</channel>
</rss>