You can use python's re.sub function. But also look into full fledged
template engines like Cheetah.
import re
txt="""
whatever
the machine with bing
10% of boo is foo
"""
h1=txt.replace("%","%%")
h3 = re.sub("", "%(\\1)s", h1)
house="something awfull"
tree="something beautifull"
print h3
Harald Armin Massa wrote:
> sth. like
> rpdict={"":"%(tree)s","":"%(house)s","%","%%"}
>
> for key, value in rpdict.iteritems():
>h1=h1.replace(key, value)
>
> but ... without the garbage, in one command.
>
> I guess there are very, very, very wise solution for this problem, but
> I do not kno
again, and again ... another try of templating
txt="""
whatever
the machine with bing
10% of boo is foo
"""
h1=txt.replace("%","%%")
h2=h1.replace("","%(tree)s")
h3=h2.replace("","%(house)s")
house="something awfull"
tree="something beautifull"
print h3 % locals()
--> the approach allows