[EMAIL PROTECTED] wrote:
> I'd like to dynamically find and invoke a method in a Python CGI.
> 
> In javascript, the running script is 'this' (Python's 'self'), except
> that 'self' is not defined.
> 
> I want to do this:
> 
> var m = this["MethodName"];  //where the method name is passed via an
> http variable
> m();  //this invokes a method in javascript
> 
> How do I do the same in python?
> 
> self["MethodName"] fails...
> 

Don't know if this is the best solution... but you need something around 
the lines of:

 >>> def foo():
...     print "bar"
...
 >>> m = locals()["foo"]
 >>>
 >>> m()
bar
 >>>

i.e., you need to play a bit with locals()

Hope that helps

-- 
Mariano

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to