Help, Search and Substitute

Pete Shinners pete at visionart.com
Fri Oct 27 16:42:22 EDT 2000


I've got to write a search and replace type routine that
works on a template file. i have a dictionary with string
keys and values. i want parse a template file and replace
"{KEYNAME}" with the value of KEYNAME from my dictionary.

i'm guessing this is where the reg-exp's come in to play?
i assume it's time i sit down and get the basics on these?

i've already written this, which handles the case with
TEMPLATE:KEYNAME on its own line, but i need to upgrade
it to substitute things out in mid-line


>>> template_test = "This {NOUN} is {ADJECTIVE}!"
>>> template_vals = {"NOUN":"parrot", "ADJECTIVE":"dead"}
>>> print template_substitute(template_test, template_vals)
"This parrot is dead!"

now i just need someone to help me write the substitute
function. any pointers on this? help is appreciated







More information about the Python-list mailing list