Keyword substitution in string

Ondrej Krajicek krajicek at ics.muni.cz
Thu Aug 12 13:43:49 EDT 2004


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

-- 
____________________________\\--//_________________________
Ondrej Krajicek              \\//      krajicek at ics.muni.cz
Institute of Computer Science,||Masaryk University Brno, CR
_____________________________//\\__________________________



More information about the Python-list mailing list