Globals and locals code
item = 'spam'
def p():
print item # <<<
for item in ['foo', 'bar']:
print item
p()
# >>> UnboundLocalError: local variable 'item' referenced before assignment
# variable global to a scope that you reassign within that scope
# is marked local to that scope by the compiler.
http://stackoverflow.com/questions/404534/python-globals-locals-and-unboundlocalerror