File: class/Workbook/Examples/Lecture5/gotchas.py

def selector():
    global X           # force X to be global
    print X
    X = 88


def outer(x):
    global inner
    def inner(i):          # assign in enclosing module
        print i,
        if i: inner(i-1)   # found in my global scope
    inner(x)

def outer(x, y):
    def inner(a=x, b=y):     # save x,y bindings/objects
        return a**b          # from the enclosing scope
    return inner

def outer(x, y):
    return lambda a=x, b=y: a**b



[Home page] Books Code Blog Python Author Train Find ©M.Lutz