Is a string formatter that pulls variables from its calling scope bad practice?
<p>I have some code that does an awful lot of string formatting, Often, I end up with code along the lines of:</p>

<pre><code>"...".format(x=x, y=y, z=z, foo=foo, ...)
</code></pre>

<p>Where I'm trying to interpolate a large number of variables into a large string.</p>

<p>Is there a good reason not to write a function like this that uses the <code>inspect</code> module to find variables to interpolate?</p>

<pre><code>import inspect

def interpolate(s):
    return s.format(**inspect.currentframe().f_back.f_locals)

def generateTheString(x):
    y = foo(x)
    z = x + y
    # more calculations go here
    return interpolate("{x}, {y}, {z}")
</code></pre>
