Variable name lookup in nested function : Variable Scope « Function « Python Tutorial






def normal():
    def action():
        return spam        
    spam = 'ni'
    return action

act = normal()
print act()








10.4.Variable Scope
10.4.1.Variable Scope and Namespaces
10.4.2.Shadow variable
10.4.3.globals() and locals()
10.4.4.create an instance to use the class simply as a namespace container
10.4.5.Variable name lookup in nested function
10.4.6.Local Names Are Detected Statically
10.4.7.Variable Scope in Functions