Cheetah template driven object output? Pythonically?

F

Fried Egg

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?
 
B

bruno at modulix

Fried said:
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?

I don't know if may be of any help, but David Mertz has done something
related (pickling/unpickling) with XML and metaclasses:

http://gnosis.cx/download/gnosis/
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,540
Members
45,024
Latest member
ARDU_PROgrammER

Latest Threads

Top