How to specify another scope for the exec statement
<p>I am tracing a function called <code>tracedFn()</code>:</p>

<pre><code>sys.settrace(traceit)
tracedFn()
sys.settrace(None)
</code></pre>

<p>the <code>tracedFn</code>:</p>

<pre><code>def tracedFn():
    foo = False
</code></pre>

<p>In the <code>traceit</code> function I would like to use exec statement to execute statements with variables in the tracedFn() like the following:</p>

<pre><code>def traceit(frame, event, trace_arg):
    if event == 'line':
        exec 'foo = True'
        print frame.f_locals
        #foo still False

return traceit
</code></pre>

<p>but when I print frame.f_locals the exec does not change the foo variable?</p>
