Observer pattern for Python

The Observer pattern is mainly used to implement a distributed event handling system. The primary objective of this pattern is to provide a way to handle run-time one-to-many relationships between objects in a loosely coupled arrangement.

Continue reading “Observer pattern for Python”

Event-based Programming for Python

Oftentimes, you need to have objects that communicate with each other via events. This is a very useful setup, for example, in a GUI — where these events represent things like mouse clicks, key strokes, or button presses. That’s not what I developed these classes for, since I was more interested in simulating things and the event system seemed like the most natural fit, but the recipe is still relevant to other event handling needs. Continue reading “Event-based Programming for Python”

Stackless Python meets Twisted Matrix….

Sometimes, you come across two programming toolkits that would go great together. However, in the case of Twisted Matrix and Stackless python, there’s some legwork required to get these two great systems to work together.

Continue reading “Stackless Python meets Twisted Matrix….”

Sending HTML Email From Python

(Due to changes in the Python standard library, I’ve posted a new updated method to send HTML email from Python.)

I forget where exactly I found this, but the other day I needed a quick Python method to send an HTML email — in my case, it was in response to a Web CGI request, but this example below is usable anywhere. The bits that need to be changed for different situations should be evident (‘somefile.txt’ for example). You will also need to point the smtplib to an actual mail server if you don’t run one on the local machine.

Continue reading “Sending HTML Email From Python”