Passing a variable number of parameters to a Python script
Hi, I wonder if anyone can help me. I have a python script in which I want to accept a variable number of parameters from a post method. ie http://Localhost:8080/apply?count=2¶m0=abc¶m1=xyz or http://Localhost:8080/apply?count=4¶m0=abc¶m1=123¶m2=rst¶m3= xyz I want to access the parameters as a list something like this: PythonScript apply(count, *args) print count for arg in args print arg Thanks Bruce.
I know that in DTML, they would be in the REQUEST dictionary... I think in python script, that corresponds to context. So they would be in context.param0, or perhaps context['param0']
From: "Bruce Pearson &/or Gwyn Ingham" <BruceP@wn.com.au> Date: Mon, 28 May 2001 09:56:23 +0800 To: "Zope" <Zope@Zope.org> Subject: [Zope] Passing a variable number of parameters to a Python script
Hi,
I wonder if anyone can help me.
I have a python script in which I want to accept a variable number of parameters from a post method.
ie http://Localhost:8080/apply?count=2¶m0=abc¶m1=xyz
or http://Localhost:8080/apply?count=4¶m0=abc¶m1=123¶m2=rst¶m3= xyz
I want to access the parameters as a list something like this:
PythonScript
apply(count, *args) print count for arg in args print arg
Thanks Bruce.
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
Thanks marc, I found using context.REQUEST.items() gave me a list of tuples that I needed. eg apply(Count): Number_of_params = int(Count) for i in range(0, Number_of_params): key = 'param' key = key + str(i) for key_pair in context.REQUEST.items(): if key == key_pair[0]: print key_pair[1]
-----Original Message----- From: zope-admin@zope.org [mailto:zope-admin@zope.org]On Behalf Of marc lindahl Sent: Monday, 28 May 2001 12:17 PM To: Zope Subject: Re: [Zope] Passing a variable number of parameters to a Pythonscript
I know that in DTML, they would be in the REQUEST dictionary... I think in python script, that corresponds to context. So they would be in context.param0, or perhaps context['param0']
I know that in DTML, they would be in the REQUEST dictionary... I think in python script, that corresponds to context. So they would be in context.param0, or perhaps context['param0']
Agh!!! context!=REQUEST!!! context and container are just ordinary objects. You can get hold of REQUEST through Acquisition as follows: REQUEST = context.REQUEST. cheers, Chris PS: How come *args and **kw don't work then?
participants (3)
-
Bruce Pearson &/or Gwyn Ingham -
Chris Withers -
marc lindahl