Cheetah template driven object output? Pythonically?

Fried Egg webb.sprague at gmail.com
Sun Jan 29 19:37:57 EST 2006


This may be trivial or stupid or both, but does anyone have a recipe
for gracefully using Cheetah to generate a text representation of an
object, but embedded in the object (so that it can be pickled,
unpickled, and told to display itself)?

Here is what I am thinking:

<pre>

import Cheetah.Template as T
class Foo:
    def __init__(self, mystate, cheetah_template='./mytemplate.tmpl'):
        self.mystate = mystate
        self._template = T.compile(<stuff>)

    def set_state(self, newstate):
        self.mystate = newstate

    def as_html(self):
         print self._template(searchlist=<SOMETHING GENERIC>)

</pre>

I guess that would work pretty well, though it is untested completely.
Has anyone done anything fairly generic and similar?  Pitfalls?




More information about the Python-list mailing list