<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <title>Snipplr</title>
    <description>Recent snippets posted on Snipplr.com</description>
    <link>https://snipplr.com/</link>
    <lastBuildDate>Tue, 09 Jun 2026 08:48:35 +0000</lastBuildDate>
    <item>
      <title>(Python) Formatting date strings in Python - chombee</title>
      <link>https://snipplr.com/view/11214/formatting-date-strings-in-python</link>
      <description>&lt;p&gt;[date](http://docs.python.org/library/datetime.html#datetime.date), [datetime](http://docs.python.org/library/datetime.html#datetime.datetime) and [time](http://docs.python.org/library/datetime.html#datetime.time) objects in Python have a [strftime](http://docs.python.org/library/datetime.html#strftime-behavior) method for creating string representations in whatever format you want. (See the strftime link for the strftime syntax.)&lt;/p&gt;</description>
      <pubDate>Thu, 15 Jan 2009 14:15:02 UTC</pubDate>
      <guid>https://snipplr.com/view/11214/formatting-date-strings-in-python</guid>
    </item>
    <item>
      <title>(Python) Import a file from a directory - chombee</title>
      <link>https://snipplr.com/view/11212/import-a-file-from-a-directory</link>
      <description>&lt;p&gt;When you want to import a python file but that file is not in the same directory as the python file you're importing _from_ (e.g. it's in a subdir). You need to add the directory that contains the file you want to import to your path environment variable `sys.path`. `sys.path` contains all the places python will look for a file when you do an import.&lt;/p&gt;</description>
      <pubDate>Thu, 15 Jan 2009 13:50:14 UTC</pubDate>
      <guid>https://snipplr.com/view/11212/import-a-file-from-a-directory</guid>
    </item>
    <item>
      <title>(Python) Creating and removing files and dirs with Python OS module - chombee</title>
      <link>https://snipplr.com/view/7318/creating-and-removing-files-and-dirs-with-python-os-module</link>
      <description>&lt;p&gt;Effbot's page on the os module: http://effbot.org/librarybook/os.htm&#13;
&#13;
The os module has lots of methods for dealing with files and directories: http://docs.python.org/lib/os-file-dir.html&#13;
&#13;
The shutil module: http://docs.python.org/lib/module-shutil.html&lt;/p&gt;</description>
      <pubDate>Tue, 15 Jul 2008 20:44:02 UTC</pubDate>
      <guid>https://snipplr.com/view/7318/creating-and-removing-files-and-dirs-with-python-os-module</guid>
    </item>
    <item>
      <title>(Python) Listing directories in Python - chombee</title>
      <link>https://snipplr.com/view/7187/listing-directories-in-python</link>
      <description>&lt;p&gt;&lt;/p&gt;</description>
      <pubDate>Wed, 09 Jul 2008 13:57:08 UTC</pubDate>
      <guid>https://snipplr.com/view/7187/listing-directories-in-python</guid>
    </item>
    <item>
      <title>(Python) Unit tests with Python - chombee</title>
      <link>https://snipplr.com/view/6739/unit-tests-with-python</link>
      <description>&lt;p&gt;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.&#13;
&#13;
This is a first attempt at a unit test for the messager.py module posted earlier.&lt;/p&gt;</description>
      <pubDate>Mon, 16 Jun 2008 10:35:25 UTC</pubDate>
      <guid>https://snipplr.com/view/6739/unit-tests-with-python</guid>
    </item>
    <item>
      <title>(Python) Messager pattern from Panda3D - chombee</title>
      <link>https://snipplr.com/view/6650/messager-pattern-from-panda3d</link>
      <description>&lt;p&gt;This is my implementation of the messager pattern used by Panda3D for event&#13;
handling. It's a really nice idea but I think Panda's version is implemented&#13;
weirdly, it uses the subscribe objects as keys in the dictionary. That means&#13;
that if you want more than one object to subscribe to the same message you&#13;
_have_ to subclass DirectObject and use self.accept(...), can't just call the&#13;
messager directly or you'll get a different behaviour, it means that a single&#13;
object instance can't subscribe two different functions to the same message, and&#13;
it means that your _objects_ have to be _hashable_ (!) because the messager uses&#13;
them as keys in a dictionary. It seems to me that it would be much simpler if&#13;
the messager's dictionary just mapped message names to function objects, so&#13;
that's what I did.&#13;
&#13;
Use this pattern when you have a lot of objects spread throughout the class&#13;
hierarchy that need to communicate with each other. It's a way of implementing&#13;
one-to-many or many-to-many communication, in which an object can send a message&#13;
to many receivers without needing to know who those receivers are, or how many&#13;
receivers there are, or even if there are any receivers (although an object can&#13;
potentially check all these things if it wants to). The singleton messager&#13;
object receives messages from broadcaster objects and forwards them to receiver&#13;
objects. Setup a single, simple, generic, system- wide messaging system, instead&#13;
of creating different systems for each different type of message or messaging&#13;
relation.&#13;
&#13;
The disadvantage of just implementing this pattern once and using it everywhere&#13;
is that with lots of senders and receivers it might become difficult to&#13;
understand and debug message-based behaviour. Particularly if the order in which&#13;
messages are sent and received becomes important, when you send a message with&#13;
this pattern there's no way of knowing in what order the receiver objects will&#13;
receive the message, and therefore know way of knowing in what order their&#13;
responses will be executed, and those responses may include sending more&#13;
messages. You can implement some ordering relations by having an object receive&#13;
a message, deal with it, then send a different message to other recievers, but I&#13;
wouldn't want to overuse that.&#13;
&#13;
Also you have to be careful to avoid clashes in message names.&#13;
&#13;
The GoF Mediator and Observer patterns are similar in that they enable a mode &#13;
of communication between objects in which the sender object broadcasts a &#13;
message without needing to know all of the receiver objects, and the receiver &#13;
objects can receive messages without being tightly coupled to the sender &#13;
object(s).&#13;
&#13;
In the GoF Mediator pattern, the Mediator object is more than just a messager &#13;
that passes messages between other objects and leaves the behaviour up to the &#13;
others. The mediator actually encapsulates the interaction behaviour between &#13;
objects, deciding which methods to call on which objects each time it receives &#13;
a notification from an object. Mediator centralises control of how objects &#13;
cooperate in the mediator class, whereas the Messager pattern leaves this &#13;
control distributed throughout the objects themselves.&#13;
&#13;
In the GoF observer pattern a one-to-many dependency is setup, there is no &#13;
separate Messager object but rather the sender object itself maintains the list &#13;
of reciever object and notifies them of new messages. With its separate &#13;
messager object the Messager pattern enables many-to-many dependencies as well &#13;
as one-to-many.&lt;/p&gt;</description>
      <pubDate>Wed, 11 Jun 2008 07:03:17 UTC</pubDate>
      <guid>https://snipplr.com/view/6650/messager-pattern-from-panda3d</guid>
    </item>
    <item>
      <title>(Python) Reading and writing text files in Python - chombee</title>
      <link>https://snipplr.com/view/6630/reading-and-writing-text-files-in-python</link>
      <description>&lt;p&gt;&lt;/p&gt;</description>
      <pubDate>Mon, 09 Jun 2008 09:48:40 UTC</pubDate>
      <guid>https://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>https://snipplr.com/view/6626/creating-listlike-objects-in-python</link>
      <description>&lt;p&gt;&lt;/p&gt;</description>
      <pubDate>Sun, 08 Jun 2008 18:34:00 UTC</pubDate>
      <guid>https://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>https://snipplr.com/view/6546/creating-dictionarylike-objects-in-python-using-dictmixin</link>
      <description>&lt;p&gt;&lt;/p&gt;</description>
      <pubDate>Mon, 02 Jun 2008 11:45:35 UTC</pubDate>
      <guid>https://snipplr.com/view/6546/creating-dictionarylike-objects-in-python-using-dictmixin</guid>
    </item>
    <item>
      <title>(Python) Adding and removing collide masks - chombee</title>
      <link>https://snipplr.com/view/6505/adding-and-removing-collide-masks</link>
      <description>&lt;p&gt;&lt;/p&gt;</description>
      <pubDate>Fri, 30 May 2008 12:20:55 UTC</pubDate>
      <guid>https://snipplr.com/view/6505/adding-and-removing-collide-masks</guid>
    </item>
    <item>
      <title>(Python) Panda3D's BitMask32 class (collision masks) - chombee</title>
      <link>https://snipplr.com/view/6504/panda3ds-bitmask32-class-collision-masks</link>
      <description>&lt;p&gt;&lt;/p&gt;</description>
      <pubDate>Fri, 30 May 2008 11:35:29 UTC</pubDate>
      <guid>https://snipplr.com/view/6504/panda3ds-bitmask32-class-collision-masks</guid>
    </item>
  </channel>
</rss>
