Substitution with Hash Values

Jeff Jones jeff at jonesj.com
Fri Apr 19 17:48:12 EDT 2002


I am a long time perl user who is trying to get a grip on python.  I
really like what I have seen so far, but I have hit a little snag
regarding substitution (like perl).

I use html templates for all of my CGI programming, and everything that needs
to be replaced is contained within double curly braces ( {{value}} ).  In
perl I use a hash to keep all of the variables that are going to replace
the placeholders in the template, and replace them the following way:

	....
	s/{{(.*?)}}/$hash{$1}/g;
	....

That substiution is accomplished as I read in the template file.

Can anyone tell me how I might do this in python?  I have tried many
different ways, but none seem to work.

Thanks.

Jeff Jones



More information about the Python-list mailing list