code1 >>> def foo(): ... a = 1 ... def bar(): ... b=2 ... print a + b ... bar() ... ... >>> foo() 3
code2 >>> def foo(): ... a = 1 ... def bar(): ... b=2 ... a = a + b ... print a ... bar() ... >>> foo() Traceback (most recent call last): File "<stdin>", line 1, in <module> File "<stdin>", line 7, in foo File "<stdin>", line 5, in bar UnboundLocalError: local variable 'a' referenced b why code2 can not get output of 3?
-- http://mail.python.org/mailman/listinfo/python-list