Suppose a template javascript string like this:
js_string = u'function hello() { alert({0}); } function goodbye() { alert({1}); }'
I would like to get following result:
function hello() { alert('Hello!'); } function goodbye() { alert('Goodbye!'); }
My initial idea was to use the .format() method, which resulted in a KeyError due to the arbitrary curly braces. I then had a look at this question and replaced said curly braces with double curly braces. Although this produces the desired result, I cannot use it, as I'm working with a rather large javascript template and am not up for changing each and every single curly brace.
I have also tried the .replace() function:
js_string.replace("{0}", repr("Hello!")).replace("{1}", repr("Goodbye!"))
However, calling .replace() more than once seems inconvenient to me, which is why I am asking if there is any straightforward alternative for this problem.