Confusing change of scope - what's going on?
<pre><code>def Test(value):
    def innerFunc():
        print value
    innerFunc()

def TestWithAssignment(value):
    def innerFunc():
        print value
        value = "Changed value"
    innerFunc()

Test("Hello 1")
# Prints "Hello 1"

TestWithAssignment("Hello 2")
# Throws UnboundLocalError: local variable 'value' referenced before assignment
# on the "print value" line
</code></pre>

<p>Why does the second one fail, given that the only difference is an assignment which comes <em>after</em> the print statement? I am pretty confused about this.</p>
