Frame Hack Recipe: Ruby-Style String Interpolation

Step 1

Implement the interpolate function, using a frame hack.

import sys
from string import Template

def interpolate(templateStr):
    """Implement this function"""

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

Expected output:

My name is Feihong. I work in Chicago.

Hints:

  1. Show hint
  2. Show hint

Solution: interpolate1.py

Go to next step