Frame Hack Recipe: Ruby-Style String Interpolation

Step 0

from string import Template

def interpolate(templateStr, d):
    t = Template(templateStr)
    return t.substitute(**d)

name = 'Feihong'
place = 'Chicago'
print interpolate("My name is ${name}. I work in ${place}.", locals())

Expected output:

My name is Feihong. I work in Chicago.

Solution: solutions/interpolate0.py

Go to next step