# Function_passing.py # This program demonstrates how to pass a function as an argument! # This works the same as when you store the command in a Button # as the callback. currentFunction = None def addFunc(x, y): print "ADD ", x+y def subtractFunc(x, y): print "SUBTRACT ", x-y def multiplyFunc(x, y): print "MULTIPLY ", x*y def storeFunction(theFunc): global currentFunction currentFunction = theFunc def callCurrent(x, y): currentFunction(x, y) def main(): # Call the store function with a function as # the parameter! #storeFunction(multiplyFunc) #storeFunction(addFunc) storeFunction(subtractFunc) # Now, let callCurrent dynamically call the # stored function! callCurrent(4, 5) main()