One nice thing about Python is triple-quotes and string
substitution make writing templates really simple
page = ''' <html><head> <title>%(title)s</title> </head><body> <h1>%(title)s</h1> The time is %(time)s. </body></html> ''' print page % { 'title': "Time of day", 'time': time.asctime() } The HTML is all by itself with only the simplest Python in the middle of it. And the substitutions are named, not positional, so it's self-documenting. You can substitute the same text more than once. And if you want to be clever, you can use locals() in place of the hand-crafted dictionary to directly substitute Python symbols. |