I know there are quite a few "python scope questions" here but I am VERY rusty with python and I am really confused about a "UnboundLocalError" problem I keep getting. I have read that 'for' loops do not have a contained scope yet my code seems to be acting in that way... My code looks like this:
`
...
for b in blocks[:]:
if b.contains(CONSTANT_NUM):
r = b.split(CONSTANT_NUM+2)
if r: blocks.append(r)
Foo= struct.unpack('<H', b.data)[0]
Bar = Foo
...
print("Foo: 0x%x" % (Foo))
`
Whenever I run this, I get the error "UnboundLocalError: local variable 'Foo' referenced before assignment". When I instead try and print Bar I get the same error. Why is the assignment not being carried outside of the 'for' loop?