O
Ondrej Krajicek
Hello,
in my application, I want to do keyword substituion in
a string from a dictionary. The problem is indeed
easy to solve, but seems quite common to me, so I wonder
wheter there is already a function in Python which
does just that.
I want to substitute values for keywords in strings,
the keywords and values are stored in a dictionary.
Something like this:
def subst(string, dict):
...
where:
subst('Hello, <key1> <key2>!', {'key1': 'Python', 'key2': 'rules' })
gives:
'Hello, Python rules!'
The keyword quoting style does not matter.
Thanks,
Ondra
in my application, I want to do keyword substituion in
a string from a dictionary. The problem is indeed
easy to solve, but seems quite common to me, so I wonder
wheter there is already a function in Python which
does just that.
I want to substitute values for keywords in strings,
the keywords and values are stored in a dictionary.
Something like this:
def subst(string, dict):
...
where:
subst('Hello, <key1> <key2>!', {'key1': 'Python', 'key2': 'rules' })
gives:
'Hello, Python rules!'
The keyword quoting style does not matter.
Thanks,
Ondra