replace %(word) in a string
Marc Boeren
M.Boeren at guidance.nl
Wed Sep 17 04:45:05 EDT 2003
Hi,
> For example with the string: "hello, %(word1) %(word2) !" and the
> dictionary: {"word1" : "python", "word2" : "lovers"} the final string
> would be: "hello python lovers"
You mean
base_string % dictionary
>>> "hello, %(word1)s %(word2)s !" % {"word1" : "python", "word2" :
"lovers"}
'hello, python lovers !'
Notice the trailing s in %(word)s!
Cheerio, Marc.
More information about the Python-list
mailing list