I was playing around with code generation of some scaffolding-style code for CodeIgniter. Initially, python’s string interpolation operator % sufficed. As time progressed, it became clearer that resorting to a templating library buys me cleaner code.
Problem #1
The $ used by Genshi for string interpolation conflicts with PHP’s $variables.
Solution #1
After 10 minutes of source [...]
Archives for the Month of June, 2008
First Encounter with Genshi
Wednesday, 4 June 2008
Python subclassing file types
Tuesday, 3 June 2008
I was hoping to write a simple tee class by subclassing file, but there must be further type magic getting in the way when print >> is used.
import sys
class tee(file):
def write(self, text):
sys.stdout.write(text)
file.write(self, text)
fd = tee("output.txt", "w")
print >> fd, "Test 1"
fd.write("Test 2\n")
$ python [...]