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

def runFunction(moduleName, functionName, argsTuple):
    exec 'import ' + moduleName
    module = eval(moduleName)
    function = getattr(module, functionName)
    return apply(function, argsTuple)

if __name__ == '__main__':
    from sys import argv
    print runFunction(argv[1], argv[2], tuple(argv[3:]))



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