running a random function
Marc 'BlackJack' Rintsch
bj_666 at gmx.net
Thu Jun 7 12:42:06 EDT 2007
In <1654405.LVbK4P6cM3 at teancum>, David Bear wrote:
> 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.
If you have a function or callable you call it with the "call operator",
which are parenthesis:
In [8]: int
Out[8]: <type 'int'>
In [9]: int()
Out[9]: 0
For a random selection of an element from a list look at the
`random.choice()` function.
Ciao,
Marc 'BlackJack' Rintsch
More information about the Python-list
mailing list