Re: calling a function from string

2007-10-22 Thread Steven D'Aprano
On Mon, 22 Oct 2007 23:16:38 +, Steven D'Aprano wrote: >> how could I call a_string as function? > > Others have suggested eval() and exec. Both will work, but have MAJOR > security implications. Oh, and they are seriously slower too. >>> import timeit >>> timeit.Timer('f("2.3")', ... 'f =

Re: calling a function from string

2007-10-22 Thread Steven D'Aprano
On Mon, 22 Oct 2007 08:54:02 +, james_027 wrote: > hi, > > i have a function that I could like to call, but to make it more dynamic > I am constructing a string first that could equivalent to the name of > the function I wish to call. That is not the right solution to dynamic functions. The

Re: calling a function from string

2007-10-22 Thread Shane Geiger
>>> exec("import datetime") ; exec("x = datetime." + "date." + "today()") >>> print x 2007-10-22 james_027 wrote: > hi, > > i have a function that I could like to call, but to make it more > dynamic I am constructing a string first that could equivalent to the > name of the function I wish to c

Re: calling a function from string

2007-10-22 Thread Bruno Desthuilliers
Jarek Zgoda a écrit : > Trent Nelson napisał(a): >>> i have a function that I could like to call, but to make it more >>> dynamic I am constructing a string first that could equivalent to the >>> name of the function I wish to call. how could I do that? the string >>> could might include name of th

Re: calling a function from string

2007-10-22 Thread Bruno Desthuilliers
james_027 a écrit : > hi, > > i have a function that I could like to call, but to make it more > dynamic I am constructing a string first that could equivalent to the > name of the function I wish to call. how could I do that? the string > could might include name of the module. > > for example >

Re: calling a function from string

2007-10-22 Thread Dustan
On Oct 22, 5:46 am, Jarek Zgoda <[EMAIL PROTECTED]> wrote: > Do not use eval(). Not only it's deprecated, it's also unsafe. I don't think it's deprecated; it doesn't say so: http://docs.python.org/lib/built-in-funcs.html#l2h-25 -- http://mail.python.org/mailman/listinfo/python-list

Re: calling a function from string

2007-10-22 Thread Dustan
On Oct 22, 4:41 am, "Francesco Guerrieri" <[EMAIL PROTECTED]> wrote: > On 10/22/07, james_027 <[EMAIL PROTECTED]> wrote: > > > hi, > > > i have a function that I could like to call, but to make it more > > dynamic I am constructing a string first that could equivalent to the > > name of the functio

Re: calling a function from string

2007-10-22 Thread Jarek Zgoda
Trent Nelson napisał(a): >> i have a function that I could like to call, but to make it more >> dynamic I am constructing a string first that could equivalent to the >> name of the function I wish to call. how could I do that? the string >> could might include name of the module. >> >> for example

RE: calling a function from string

2007-10-22 Thread Trent Nelson
> i have a function that I could like to call, but to make it more > dynamic I am constructing a string first that could equivalent to the > name of the function I wish to call. how could I do that? the string > could might include name of the module. > > for example > > a_string = 'datetime.' +

Re: calling a function from string

2007-10-22 Thread Francesco Guerrieri
On 10/22/07, james_027 <[EMAIL PROTECTED]> wrote: > hi, > > i have a function that I could like to call, but to make it more > dynamic I am constructing a string first that could equivalent to the > name of the function I wish to call. how could I do that? the string > could might include name of t

calling a function from string

2007-10-22 Thread james_027
hi, i have a function that I could like to call, but to make it more dynamic I am constructing a string first that could equivalent to the name of the function I wish to call. how could I do that? the string could might include name of the module. for example a_string = 'datetime.' + 'today()'