Re: is there an equivalent of javascript's this[myMethod] for the currently running script?
Yes, that is exactly what I was looking for. Thank you. I will read more about 'locals()', but a quick test proved you right. -- http://mail.python.org/mailman/listinfo/python-list
Re: is there an equivalent of javascript's this[myMethod] for the currently running script?
'self' is not defined in this circumstance. The poster above (using 'locals()') has it right. -- http://mail.python.org/mailman/listinfo/python-list
Re: is there an equivalent of javascript's this[myMethod] for the currently running script?
getattr does not work on a running script (afaik) because 'self' is undefined. The poster above got it right using 'locals()' -- http://mail.python.org/mailman/listinfo/python-list
is there an equivalent of javascript's this[myMethod] for the currently running script?
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... -- http://mail.python.org/mailman/listinfo/python-list
Re: is there an equivalent of javascript's this[myMethod] for the currently running script?
[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
Re: is there an equivalent of javascript's this[myMethod] for the currently running script?
[EMAIL PROTECTED] wrote: I'd like to dynamically find and invoke a method in a Python CGI. getattr(self, methodName)() But make sure to validate user input first, of course. -- http://mail.python.org/mailman/listinfo/python-list
Re: is there an equivalent of javascript's this[myMethod] for the currently running script?
[EMAIL PROTECTED] enlightened us with: var m = this[MethodName]; m(); //this invokes a method in javascript How do I do the same in python? getattr. Read the documentation, it's all in there. Sybren -- The problem with the world is stupidity. Not saying there should be a capital punishment for stupidity, but why don't we just take the safety labels off of everything and let the problem solve itself? Frank Zappa -- http://mail.python.org/mailman/listinfo/python-list
Re: is there an equivalent of javascript's this[myMethod] for the currently running script?
[EMAIL PROTECTED] wrote: I'd like to dynamically find and invoke a method in a Python CGI. boundmeth = obj.meth # nb: no () # stuff. boundmeth() # call it, with args if needed -- http://mail.python.org/mailman/listinfo/python-list