David Bear said unto the world upon 06/07/2007 11:56 AM: > I would like to write some code that would randomly select a function from a > list of functions and call it. I was looking in the globals names space and > randomly selecting items that were of type function.. but I didn't see a > way of actually running the function. > > Any pointers? >
Unless I've missed your meaning: >>> import random >>> def f(): print 42 ... >>> def g(): print 24 ... >>> funcs = [f,g] >>> random.choice(funcs)() 24 Best, Brian vdB -- http://mail.python.org/mailman/listinfo/python-list