The problem is that when python sees the destination inside the function, then it treats this variable as a local variable and will not extract its value from the closing or global scope when the function is executed.
args = ['blah']
foo = 'bar'
def func():
print foo
foo = 'spam'
print foo
func()
Output:
File "/home/monty/py/so.py", line 6, in <module>
func()
File "/home/monty/py/so.py", line 3, in func
print foo
UnboundLocalError: local variable 'foo' referenced before assignment
Note that if it foois a mutable object here, and you are trying to perform an in-place operation on it, then python will not complain about it.
foo = []
def func():
print foo
foo.append(1)
print foo
func()
Output:
[]
[1]
: UnboundLocalError, ?