I'm wondering if there's a way to create a string that will allow % plus arguments to follow. So basically splitting up
print "this is a string %s"%("this is another string")
In to two parts, allowing the first to be dynamic.
This is an example of how you would do it with your own function.
def dyn_string(x, d):
for key in d.keys():
x = x.replace("<%s>"%key, d[key])
return x
x = """One day, <noun> decided to post a <adjective> question on <noun2>.
Even though <noun>'s <adverb> for a better alternative, <noun> is <adjective2> with what <noun>'s got working.
"""
print dyn_string(x, {"noun":"Sane", "adjective":"stupid", "noun2":"PFO", "adverb":"hoping", "adjective2":"happy"})
Is there a built in method for the same result? Idealy I'd like it to work like so:
x = "this is a string %s"
print x%"this is another string"
But obviously that doesn't work.
EDIT HOLY CRAP. I feel so stupid. It actually does work... god...
/EDIT
I want this so I can take a dynamic template and stick in specific values appropriately.