Archive for the ‘ Python Tips and Tricks ’ Category
As any good python developer does, I make heavy use of python’s iterator protocol. It’s easy, it’s efficient, it’s a good thing. As you know, an iterator consumes an iterable piece by piece each time “next” is called — which means that the next value cannot be peeked without incrementing the iterator (thus consuming the [ READ MORE ]
Ok. So recently I posted some code for a simple templating utility that I wrote. I’ve done some refactoring and have an even cooler version. This version better extends the behavior of string.Template and I’ve found it to be far more intuitive to use. Without further ado: import string class SimpleTemplate(string.Template): """ [ READ MORE ]
Ready for the simplest templating utility ever? I was trying to prepare some JSON data stored in a tree and needed some simple code to generate templated text. Below is a wrapper for python’s string.Template class: import string class SimpleTemplate(string.Template): """ Takes a string template and a tuple or list of identifier names [ READ MORE ]