Multiple string.replace in one run

Thomas Güttler guettler at thomas-guettler.de
Fri Jun 20 07:16:54 EDT 2003


Hi!

I want to replace strings in a file:
 $VAR$ should be replaced with "foo".

I could do this with string.replace, but
if I want to replace several variables, I need to
do the replace several times. Since the file could
be very long I am searching for a better solution.

How can I replace several variables at once?

Example:

foo.html:
<html>
 <head>
  <title>$TITLE</title>
 </head>
 <body>
  $TITLE
  $TABLE_overview$
  blu, blu
 </body>
</html> 

myreplace({"TITLE": "my title", 
           "TABLE_overview": "Look"}, foo_content)

upto now:
foo_content.replace("$TITLE$", "my title").replace("TABLE_overview", "Look")

 thomas





More information about the Python-list mailing list