list of functions question
Tim Roberts
timr at probo.com
Thu Apr 27 03:21:47 EDT 2006
val bykoski <val at vtek.com> wrote:
>
>Hi The List:
> I have a modeling app where i'm detecting events (in temporal
>dynamics) applying a set of (boolean) functions - kind of:
>
>event_list = "f1 f2 etc".split() # each fi detects a specific event
>i have defs for functions fi, or simple boolean expressions for each, so
>that evList is a list of defs or boolean expressions
>for ev in evList:
> if ev: # this supposedly is a call ev(t)
> # doing smth with the event
>
> I didn't succeed, though, (blindly) trying various options.
>I thought/tried "apply()" but couldn't get it work.
>I'd appreciate pointers to how to handle this kind of
>functions or events lists (or objects?) and how to call those
>functions in a loop.
If you hadn't tried the string shortcut, it would have worked:
event_list = [f1, f2, etc]
As it is, event_list is a list of strings, not a list of functions.
Then, when you want to call it, remember that it has to be treated like a
function:
for ev in event_list:
if ev(t):
pass
If you REALLY need the list of functions to come from a string, you can
also do:
event_list = [eval(f) for f in "f1 f2 etc".split()]
--
- Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.
More information about the Python-list
mailing list