Re: [Numpy-discussion] function name as parameter

2010-10-21 Thread Johann Cohen-Tanugi
On 10/20/2010 11:49 PM, Zachary Pincus wrote: >> Hi Robert, >> so in a big data analysis framework, that is essentially written in C >> ++, >> exposed to python with SWIG, plus dedicated python modules, the user >> performs an analysis choosing some given modules by name,as in : >> myOpt="foo" >>

Re: [Numpy-discussion] function name as parameter

2010-10-20 Thread Dag Sverre Seljebotn
Johann Cohen-Tanugi wrote: > On 10/20/2010 11:10 PM, Robert Kern wrote: > >> On Wed, Oct 20, 2010 at 15:58, Johann Cohen-Tanugi >> wrote: >> >> >>> On 10/20/2010 10:35 PM, Nathaniel Smith wrote: >>> >>> >> >> IMPORTANT USAGE NOTE: never do this :-)

Re: [Numpy-discussion] function name as parameter

2010-10-20 Thread Robert Kern
On Wed, Oct 20, 2010 at 16:49, Zachary Pincus wrote: > But why not have the user just pass in the relevant optObject from the > pyOpt namespace (or some restricted namespace that just has the > relevant functions exposed)? E.g. > my_analysis.perform(optimizer=pyOpt.Amoeba) > rather than > my_anal

Re: [Numpy-discussion] function name as parameter

2010-10-20 Thread Zachary Pincus
> Hi Robert, > so in a big data analysis framework, that is essentially written in C > ++, > exposed to python with SWIG, plus dedicated python modules, the user > performs an analysis choosing some given modules by name,as in : > myOpt="foo" > my_analyse.perform(use_optimizer=myOpt) > > The attri

Re: [Numpy-discussion] function name as parameter

2010-10-20 Thread Johann Cohen-Tanugi
On 10/20/2010 11:10 PM, Robert Kern wrote: > On Wed, Oct 20, 2010 at 15:58, Johann Cohen-Tanugi > wrote: > >> On 10/20/2010 10:35 PM, Nathaniel Smith wrote: >> > >>> IMPORTANT USAGE NOTE: never do this :-) >>> >>> >> What would you recommand? I do encounter situations where

Re: [Numpy-discussion] function name as parameter

2010-10-20 Thread Nathaniel Smith
On Wed, Oct 20, 2010 at 1:58 PM, Johann Cohen-Tanugi wrote: > On 10/20/2010 10:35 PM, Nathaniel Smith wrote: >> The better way to do this is: >> >> import inspect >> def call_this(fname, x): >>   caller_frame = inspect.currentframe().f_back >>   f = caller_frame.f_locals.get(fname, caller_frame.f_

Re: [Numpy-discussion] function name as parameter

2010-10-20 Thread Robert Kern
On Wed, Oct 20, 2010 at 15:58, Johann Cohen-Tanugi wrote: > On 10/20/2010 10:35 PM, Nathaniel Smith wrote: >> IMPORTANT USAGE NOTE: never do this :-) >> > What would you recommand? I do encounter situations where I need > instantiation based on the name of the thing to instantiate, typically > pa

Re: [Numpy-discussion] function name as parameter

2010-10-20 Thread Johann Cohen-Tanugi
On 10/20/2010 10:35 PM, Nathaniel Smith wrote: > On Wed, Oct 20, 2010 at 6:51 AM, Johann Cohen-Tanugi > wrote: > >> If you really need to pass the function name : >> In [3]: def my_func(x): >> ...: return 2*x >> >> In [4]: def caller(fname,x): >> ...: return eval("%s(%f)"%(f

Re: [Numpy-discussion] function name as parameter

2010-10-20 Thread Nathaniel Smith
On Wed, Oct 20, 2010 at 6:51 AM, Johann Cohen-Tanugi wrote: > If you really need to pass the function name : > In [3]: def my_func(x): >    ...:     return 2*x > > In [4]: def caller(fname,x): >    ...:     return eval("%s(%f)"%(fname,x)) > > In [5]: caller("my_func",2) > Out[5]: 4.0 The better w

Re: [Numpy-discussion] function name as parameter

2010-10-20 Thread Thomas Kirk Gamble
On Wed, 2010-10-20 at 13:18 -0400, Alan G Isaac wrote: > On 10/20/2010 9:42 AM, Thomas Kirk Gamble wrote: > > I'm trying to write an implementation of the amoeba function from > > numerical recipes and need to be able to pass a function name and > > parameter list to be called from within the amoeb

Re: [Numpy-discussion] function name as parameter

2010-10-20 Thread Alan G Isaac
On 10/20/2010 9:42 AM, Thomas Kirk Gamble wrote: > I'm trying to write an implementation of the amoeba function from > numerical recipes and need to be able to pass a function name and > parameter list to be called from within the amoeba function. 1. Have you checked whether this might already be

Re: [Numpy-discussion] function name as parameter

2010-10-20 Thread Thomas Kirk Gamble
On Wed, 2010-10-20 at 09:46 -0400, Zachary Pincus wrote: > > I'm trying to write an implementation of the amoeba function from > > numerical recipes and need to be able to pass a function name and > > parameter list to be called from within the amoeba function. Simply > > passing the name as a str

Re: [Numpy-discussion] function name as parameter

2010-10-20 Thread josef . pktd
On Wed, Oct 20, 2010 at 9:46 AM, Zachary Pincus wrote: >> I'm trying to write an implementation of the amoeba function from >> numerical recipes and need to be able to pass a function name and >> parameter list to be called from within the amoeba function.  Simply >> passing the name as a string d

Re: [Numpy-discussion] function name as parameter

2010-10-20 Thread Johann Cohen-Tanugi
If you really need to pass the function name : In [3]: def my_func(x): ...: return 2*x In [4]: def caller(fname,x): ...: return eval("%s(%f)"%(fname,x)) In [5]: caller("my_func",2) Out[5]: 4.0 On 10/20/2010 03:46 PM, Zachary Pincus wrote: >> I'm trying to write an implementation

Re: [Numpy-discussion] function name as parameter

2010-10-20 Thread Zachary Pincus
> I'm trying to write an implementation of the amoeba function from > numerical recipes and need to be able to pass a function name and > parameter list to be called from within the amoeba function. Simply > passing the name as a string doesn't work since python doesn't know it > is a function and

[Numpy-discussion] function name as parameter

2010-10-20 Thread Thomas Kirk Gamble
I'm trying to write an implementation of the amoeba function from numerical recipes and need to be able to pass a function name and parameter list to be called from within the amoeba function. Simply passing the name as a string doesn't work since python doesn't know it is a function and throws a