intertwingly

It’s just data

Unbuffered Cheetah


The normal mode of operation for Cheetah is that template + [dict] = string, and you can do whatever you want with the string, however I have a scenario where I have a lot of data and I want to intermix other content into the output stream.

The solution appears to be to simulate running a WebWare transaction, and you can control the I/O yourself:

 import sys
 from Cheetah.Template import Template
 
 class webtrans:
   def _init_(self,file):
     self.file=file
   def response(self):
     return self
   def write(self,text):
     self.file.write(text)

 data = {'foo':'xyzzy'}
 t=Template('Result: $foo', [data])
 t.respond(webtrans(sys.stdout))