Re: Getting a function name from string

2007-05-08 Thread Carsten Haese
On Tue, 8 May 2007 09:38:48 +0200, Cesar Härdfeldt wrote > [...]   > I now have 'module' and 'function' as strings and 'parms' normally as a list > of strings. I can import the module by __import__(module) but is there > another way to call: > module.function(parms) than using eval()? function_t

Getting a function name from string

2007-05-08 Thread Cesar Härdfeldt
" It has been my experience that, more often than not, any time you think you want to evaluate strings, you don't need to. For instance, instead of passing around the name of the function as a string: s = "someFunction" eval(s)() you can pass around the function as an object: s = someFunction

Re: Getting a function name from string

2005-11-03 Thread Mike Meyer
[EMAIL PROTECTED] (Bengt Richter) writes: >>For a lot of uses, it'd be better to build the dictionary by hand >>rather than relying on one of the tools that turns a namespace into a >>dictionary. > IMO it would be nice if name lookup were as cleanly > controllable and defined as attribute/method lo

Re: Getting a function name from string

2005-11-03 Thread Bengt Richter
On Wed, 02 Nov 2005 19:01:46 -0500, Mike Meyer <[EMAIL PROTECTED]> wrote: >"Paul McGuire" <[EMAIL PROTECTED]> writes: >> "David Rasmussen" <[EMAIL PROTECTED]> wrote in message >> news:[EMAIL PROTECTED] >>> If I have a string that contains the name of a function, can I call it? >>> As in: >>> >>> d

Re: Getting a function name from string

2005-11-02 Thread Steven D'Aprano
David Rasmussen wrote: > If I have a string that contains the name of a function, can I call it? > As in: > > def someFunction(): > print "Hello" > > s = "someFunction" > s() # I know this is wrong, but you get the idea... py> eval("someFunction()") 'Hello' py> eval(s)() # note the second

Re: Getting a function name from string

2005-11-02 Thread Mike Meyer
"Paul McGuire" <[EMAIL PROTECTED]> writes: > "David Rasmussen" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] >> If I have a string that contains the name of a function, can I call it? >> As in: >> >> def someFunction(): >> print "Hello" >> >> s = "someFunction" >> s() # I know this

Re: Getting a function name from string

2005-11-02 Thread Paul McGuire
"David Rasmussen" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > If I have a string that contains the name of a function, can I call it? > As in: > > def someFunction(): > print "Hello" > > s = "someFunction" > s() # I know this is wrong, but you get the idea... > > /David Lookup th

Getting a function name from string

2005-11-02 Thread David Rasmussen
If I have a string that contains the name of a function, can I call it? As in: def someFunction(): print "Hello" s = "someFunction" s() # I know this is wrong, but you get the idea... /David -- http://mail.python.org/mailman/listinfo/python-list