running a random function
Matimus
mccredie at gmail.com
Thu Jun 7 12:50:30 EDT 2007
How are you making the list of functions? Something like this:
[code]
fs = []
for k,f in globals():
if callable(f):
fs.append(f)
[/code]
Then to call a random one (assuming they all take no parameters):
[code]
import random
random.choice(fs)()
[/code]
Or maybe you only have the name of the function, this should work:
[code]
globals()[name]()
[/code]
Does this help? I'm not really clear on what you are asking for.
More information about the Python-list
mailing list