# Templates are used to display an object in HTML import DocumentTemplate class Food: "Something edible" def __init__(self,name,calories): self.name=name self.calories=calories def is_fattening(self): if self.calories > 100: return 1 index_html=DocumentTemplate.HTML("""\ <html> <p>Food: <!--#var name--></p> <p>Calories: <!--#var calories--></p> <!--#if is_fattening--> <p><blink>Warning: Do Not Eat!</blink></p> <!--#/if--> </html>""") # create a Food object, spam spam=Food("SPAM",250) # display it with its template print spam.index_html(spam)
Bobo and Principia (Web Techniques, Feb 1999)
Related Reading
More Insights
INFO-LINK
To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy. | |