I'm going to consider using it though. There are probably plenty of cases where it would be more readable than using the % operator--I can recall a couple times in code I wrote very recently.
In step 1 of Frame Hacks recipe #1, Feihong and Kumar how how one can write a function that wraps string.Template and the substitute method so the mapping argument (and optional keyword arguments) don't need to be provided.
SPOILER WARNING
def interpolate(templateStr):
import sys
from string import Template
t = Template(templateStr)
frame = sys._getframe(1)
return t.substitute(**frame.f_locals)
name = 'Feihong'
place = 'Chicago'
print interpolate("My name is ${name}. I work in ${place}.")
def interpolate(templateStr, **kws):
from string import Template
return Template(templateStr).substitute(kws)
name = 'Feihong'
place = 'Chicago'
print interpolate("My name is ${name}. I work in ${place}.",
name=name, place=place)
The solution for step 2 of recipe #1 (which I showed a partial solution for when I wrote about Frame Hacks) allows for expressions in the template strings. I don't think I've run across a use case for that, but I'll write about it if I do.
I should also mention that Python 3.0 will include a new (third) method of string interpolation, the format method to be added to the built-in string class. (There's more to it than just that. You can read all about it in PEP 3101. And if--like me--you don't know just what a PEP is, I recommend reading the "PEPs" section hear the top of the description of Python's Development Process. And you'll find plenty more detail in PEP 1.)
The above example would look like this using the new format method:
name = 'Feihong'
place = 'Chicago'
print "My name is {name}. I work in {place}.".format(name=name, place=place)
TODO
I haven't installed the latest Python 3.0 alpha yet. I should make time to do so and play with the above.