Cheetah template driven object output? Pythonically?

Discussion in 'Python' started by Fried Egg, Jan 30, 2006.

  1. Fried Egg

    Fried Egg Guest

    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:


    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>)


    I guess that would work pretty well, though it is untested completely.
    Has anyone done anything fairly generic and similar? Pitfalls?
    Fried Egg, Jan 30, 2006
    1. Advertisements

  2. I don't know if may be of any help, but David Mertz has done something
    related (pickling/unpickling) with XML and metaclasses:
    bruno at modulix, Jan 30, 2006
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.