[Tutor] HTML/text formatting question

Kent Johnson kent37 at tds.net
Wed Aug 3 20:58:48 CEST 2005

Smith, Jeff wrote:
> I have a tool that outputs data in either html or text output.
> Currently I'm writing chucks like:
> if html:    
>     print '<html><body bgcolor="FFFFCC">'
>     print '<table border="1" bgcolor="CCCCFF" width="800">'
>     print '<tr><td colspan="2"><h2>'
> print 'Differences %s: %s' % (htypestr, lbl1)
> if html:

You might want to consider some kind of template library; there are many to choose from. Generally speaking they merge a template and a data model. You would have a common data model and two templates - one for HTML and one for plain text.

There are many Python template libraries to choose from; a relatively simple one is in this recipe: 

Many more are listed here in the Templating Engines section:


More information about the Tutor mailing list