Template for CGI

Jen Chu JenChu at news.vex.net
Tue Nov 2 20:55:15 CET 1999

On Tue, 2 Nov 1999 10:47:10, Glenn Kidd <gek8365 at garnet.acns.fsu.edu> wrote:
>Is there a way to embed variables into a teplate or a replace function in
>Python?  Thank you for any help you give.

Real easy to map varables to strings in Python. I use this trick all
the time for HTML templates. You can map dictionary values into a string.
Consider the following code:

dict = {
    'text': 'html text',
    'iheight': 32,
    'HR': '<HR>',

textfile = """\
This isn't real %(text)s.
<IMG height="%(iheight)s">

print textfile % dict

This isn't real html text.
<IMG height="8">

More information about the Python-list mailing list