Cheetah template driven object output? Pythonically?
bruno at modulix
onurb at xiludom.gro
Mon Jan 30 10:16:46 EST 2006
Fried Egg wrote:
> 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?
I don't know if may be of any help, but David Mertz has done something
related (pickling/unpickling) with XML and metaclasses:
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in 'onurb at xiludom.gro'.split('@')])"
More information about the Python-list