Re: Need to call functions/class_methods etc using string ref :How

2007-12-03 Thread Ravi Kumar
WOW, Thanks a lot. I got many options to do, and play with. Each one having its own pros and cons. But for my requirement in project, i will go with hasattr/getattr/callable and then calling the ref method. It seems fit for the problem. Thanks a lot :) again. On Dec 1, 2007 12:45 AM, Bruno Desthu

Re: Need to call functions/class_methods etc using string ref :How

2007-11-30 Thread Bruno Desthuilliers
George Sakkis a écrit : > On Nov 26, 2:04 pm, Bruno Desthuilliers > > <[EMAIL PROTECTED]> wrote: > >>Donn Ingle a écrit : >> >> I see someone already showed you eval. Eval is evil. Don't use it. Especially if the functions are coming to you from a public URL! >> >>>Yes, I suggested to h

Re: Need to call functions/class_methods etc using string ref :How

2007-11-26 Thread George Sakkis
On Nov 26, 2:04 pm, Bruno Desthuilliers <[EMAIL PROTECTED]> wrote: > Donn Ingle a écrit : > > >>I see someone already showed you eval. Eval is evil. Don't use it. > >>Especially if the functions are coming to you from a public URL! > > > Yes, I suggested to him (by email) this: > > > thisinstanc

Re: Need to call functions/class_methods etc using string ref :How

2007-11-26 Thread Bruno Desthuilliers
Donn Ingle a écrit : >>target = >>for funcname in funclist: >>func = getattr(target, funcname, None) >>if callable(func): >>func(*args, **kwargs) > > Nice. 'callable' is new to me. What about getattr, then ?-) And FWIW, callable will disappear in py3k... (anyway, you can just test if the objec

Re: Need to call functions/class_methods etc using string ref :How

2007-11-26 Thread Donn Ingle
> target = > for funcname in funclist: > func = getattr(target, funcname, None) > if callable(func): > func(*args, **kwargs) Nice. 'callable' is new to me. Live and learn :) \d -- http://mail.python.org/mailman/listinfo/python-list

Re: Need to call functions/class_methods etc using string ref :How

2007-11-26 Thread Bruno Desthuilliers
Donn Ingle a écrit : >>I see someone already showed you eval. Eval is evil. Don't use it. >>Especially if the functions are coming to you from a public URL! > > Yes, I suggested to him (by email) this: > > thisinstance = SomeObject.__class__.__dict__ > This will only get attributes defined

Re: Need to call functions/class_methods etc using string ref :How

2007-11-26 Thread Donn Ingle
> I see someone already showed you eval.  Eval is evil.  Don't use it. > Especially if the functions are coming to you from a public URL! Yes, I suggested to him (by email) this: thisinstance =  SomeObject.__class__.__dict__ for f in yourlist:  if f in thisinstance: eval(f)(params) Which would

Re: Need to call functions/class_methods etc using string ref :How

2007-11-26 Thread J. Clifford Dyer
On Mon, Nov 26, 2007 at 04:07:03PM +0530, Ravi Kumar wrote regarding Need to call functions/class_methods etc using string ref :How: > >Hi, >First of all, since this is my first mail to Python-List, I want to say >"Hello world!" >After that; >I am

Re: Need to call functions/class_methods etc using string ref :How

2007-11-26 Thread Donn Ingle
Well, I don't know all the answers, but you can start here: def boobs(): print "Oohh little birds!" b="boobs" >>>eval(b)() Ohhh little birds! Naturally, eval is going to run anything... Even code to format your drive. HTH \d -- http://mail.python.org/mailman/listinfo/python-list

Need to call functions/class_methods etc using string ref :How

2007-11-26 Thread Ravi Kumar
Hi, First of all, since this is my first mail to Python-List, I want to say "Hello world!" After that; I am stuck in a project. Actually I am writing a module (for testing now), which takes URL, parses it, finds which modules and then which method to call or which class to initiate and which string