passing *args to external method
Hi List! I've been trying without success to pass from a form in ZPT to an external method an undefined list of parameters (*args). An example: def external_method(var_fix,*args): return 'Vals',var_fix,args ... file _sub_html_: <FORM ACTION="external_method" METHOD="POST" ENCTYPE="multipart/form-data"> <input type="text" name="var_fix" value=""> <input type="hidden" name="arg1" value="test1"> <input type="hidden" name="arg2" value="test2"> <INPUT TYPE="SUBMIT" VALUE="Submit"> </FORM> returns typed value for var_fix and () for args. However, if I do: def external_method(var_fix,arg1,arg2,*args): return "Vals",var_fix,arg1,arg2,args it returns values of arg1 and arg2. But my problem is that the number args cannot be fixed since such arguments depends on other page. I hope one can understand it. And I'd appreciate very much any attention. Many thanks in advance. Cheers, Alan -- Alan Wilter S. da Silva, D.Sc. - Research Associate Department of Biochemistry, University of Cambridge. 80 Tennis Court Road, Cambridge CB2 1GA, UK.
--On 12. September 2006 18:26:20 +0100 Alan <alanwilter@gmail.com> wrote:
it returns values of arg1 and arg2. But my problem is that the number args cannot be fixed since such arguments depends on other page.
All form parameter are available from the REQUEST.form. self.REQUEST gives you the REQUEST object inside an external method. 'form' is basically a dict-like object so you can use the standard Python methods for dicts for doing whatever you want. -aj
Alan wrote at 2006-9-12 18:26 +0100:
I've been trying without success to pass from a form in ZPT to an external method an undefined list of parameters (*args).
An example:
def external_method(var_fix,*args): return 'Vals',var_fix,args
This will not work. "ZPublisher" must know the argument names to be able to pass values to them -- for 2 reasons: 1. HTTP uses named request parameters; there is no straighforward translation into a sequence of positional parameters. 2. The request contains a lot of potentially relevant parameters (beside the content of "form", we also have "cookies" and "environ" and "self"). Without the names, "ZPublisher" does not know which of them to pass (even when you function accepts arbitrary keyword parameters). -- Dieter
participants (3)
-
Alan -
Andreas Jung -
Dieter Maurer