On Aug 30, 8:10 pm, Scott David Daniels <[EMAIL PROTECTED]> wrote: > Marc 'BlackJack' Rintsch wrote: > > A fine repy > > > In [57]: funcs = [a, b] > > In [58]: funcs > > Out[58]: [<function a at 0xb7792e2c>, <function b at 0xb779e1ec>] > > > In [59]: funcs[0]() > > Out[59]: 1 > > > In [60]: funcs[1]() > > Out[60]: 2 > > and a "list comprehension" allows you to call these things no matter how > long the list is. > > So after the above: > >>> results = [f() for f in funcs] > >>> print results > [1, 2]
You can also use exec, but someone will tell you that the sky is going to fall if you do. I am one of the ones who think that calling a function with results = [f() for f in funcs] doesn't "work" because it gives a meaningless error message that the calling line didn't work. There is already enough discussion about this, so if you use "some_string()" to call a function, wrap it in a try/except with a traceback. -- http://mail.python.org/mailman/listinfo/python-list