Archive for the ‘Articles’ Category.

Python WSGI Middleware for automatic Gzipping

I've just started learning Python WSGI (PEP-333) and thought the best way to learn would be to write some WSGI tools myself. Most recently, I chose to write a middleware application that converts all output into valid gzipped data. In this article, I will be demonstrating how my middleware gzipper works and how to implement it.

Continue reading 'Python WSGI Middleware for automatic Gzipping' »

Simple Output Buffering in Python

Recently, I needed a quick and simple solution to buffer output of a few Python scripts. When I went to look for a module, I was astonished to find that one didn't exist. I quickly decided to change this. In this article, we'll discuss simple ways to buffer output using StringIO and I'll introduce my output buffering module that I constructed.

Continue reading 'Simple Output Buffering in Python' »

Near-Implicit String Interpolation in Python

A great thing about working in Python is that it provides you with numerous methods of string formatting and interpolation. Unfortunately, it isn't as implicit as it is in PHP, where just using double-quotes will parse the string. In Python at the very minimum string interpolation requires the use of the modulo operator (%) or a custom-built function. In this article, we'll discuss building a string interpolation function using the string.Template object and Python 3.0's format method.

Continue reading 'Near-Implicit String Interpolation in Python' »

XOR Encryption With Python

XOR encryption is a great solution to go with when a task requires that a piece of data is encrypted with a key when one doesn't have the means to use a more well-rounded algorithm. I've used it on a few occasions with great success. In this document, we'll discuss how to code the XOR cipher in Python and we'll cover the pros and cons of using it.

Continue reading 'XOR Encryption With Python' »

Ternary Operator in Python - People got Clever

The ternary operator can be incredibly useful in numerous situations in Python, which is why I'm surprised that prior to Python 2.5, there was no standard way of using one. In this article, we'll cover the ternary operator that was added in Python 2.5 along with the numerous ways that people emulated the operator before then.

Continue reading 'Ternary Operator in Python - People got Clever' »