This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author vpodpecan
Recipients vpodpecan
Date 2009-04-15.15:10:41
SpamBayes Score 8.9665645e-07
Marked as misclassified No
Message-id <1239808247.23.0.84220378754.issue5763@psf.upfronthosting.co.za>
In-reply-to
Content
Consider the following two functions:

def outer():
    a = 1
    def inner():
        print a
    
    inner()
#end outer()


def outer_BUG():
    a = 1
    def inner():
        print a
        a = 2
    
    inner()
#end outer_BUG()

The first function outer() works as expected (it prints 1), but the
second function ends with an UnboundLocalError, which says that the
"print a" statement inside inner() function references a variable before
assignment. Somehow, the interpreter gets to this conclusion by looking
at the next statement (a = 2) and forgets the already present variable a
from outer function.

This was observed with python 2.5.4 and older 2.5.2. Other releases were
not inspected.

Best regards,
Vid
History
Date User Action Args
2009-04-15 15:10:47vpodpecansetrecipients: + vpodpecan
2009-04-15 15:10:47vpodpecansetmessageid: <1239808247.23.0.84220378754.issue5763@psf.upfronthosting.co.za>
2009-04-15 15:10:44vpodpecanlinkissue5763 messages
2009-04-15 15:10:42vpodpecancreate