File: class/Workbook/Examples/Lecture9/inspecting.py

def func(x):
    a = 1
    print locals()                # on function call
    print globals().keys()

class klass:
    def __init__(self):
        print locals()            # on instance creation
        print globals().keys()
    print locals()                # on class creation
    print globals().keys()

def nester(L, M, N):
    class nested:               # assigns class to name
        def __init__(self):
            pass
        print locals()          # local=class global=mod
        print globals().keys()  # no access to L/M/N!
    return nested                



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