Re: Calling an arbitrary function with the right arguments

2010-09-27 Thread Jean-Michel Pichavant
John O'Hagan wrote: How to call a function with the right arguments without knowing in advance which function? For example: import random def f1(): pass def f2(foo): pass def f3(foo, bar): pass foo=random.choice((1,2,3)) bar=random.choice((1,2,3)) myfunc=random.choice((f1, f2,

Re: Calling an arbitrary function with the right arguments

2010-09-27 Thread Peter Otten
John O'Hagan wrote: > How to call a function with the right arguments without knowing in advance > which function? For example: > > import random > > def f1(): > pass > > def f2(foo): > pass > > def f3(foo, bar): > pass > > foo=random.choice((1,2,3)) > bar=random.choice((1,2,3)) >

Re: Calling an arbitrary function with the right arguments

2010-09-27 Thread Bruno Desthuilliers
John O'Hagan a écrit : How to call a function with the right arguments without knowing in advance which function? (snip) For most use case I can think of, I can only second Steven and Chris - if your functions are interchangeable then they should have a same API. Now there's at least one u

Re: Calling an arbitrary function with the right arguments

2010-09-26 Thread Chris Rebert
On Sun, Sep 26, 2010 at 8:41 PM, John O'Hagan wrote: > How to call a function with the right arguments without knowing in advance > which function? For example: > > import random > > def f1(): >    pass > > def f2(foo): >    pass > > def f3(foo, bar): >    pass > > foo=random.choice((1,2,3)) > bar

Re: Calling an arbitrary function with the right arguments

2010-09-26 Thread Steven D'Aprano
On Mon, 27 Sep 2010 03:41:13 +, John O'Hagan wrote: > How to call a function with the right arguments without knowing in > advance which function? For example: > > import random > > def f1(): > pass > > def f2(foo): > pass > > def f3(foo, bar): > pass > > foo=random.choice((1

Calling an arbitrary function with the right arguments

2010-09-26 Thread John O'Hagan
How to call a function with the right arguments without knowing in advance which function? For example: import random def f1(): pass def f2(foo): pass def f3(foo, bar): pass foo=random.choice((1,2,3)) bar=random.choice((1,2,3)) myfunc=random.choice((f1, f2, f3)) How to call myfu