Passing not-string variables to a python script
Hi, I was hoping that I could get some help with this one, without looking too thick. I'm finding whenever I call a python script from within a zope page (as opposed to submitting a form to a script), it assumes that every parameter is a string. This isn't always the case, in fact, it is rarely the case. I was wondering if there was anyway that I could force it to know what type it was. I am particularly interested in passing in lists. The way I call it at the moment is like this: <dtml-var expr="script1(var1='blah', var2=['a', 'b', 'c'])"> etc. I tried calling them like var1:string, var2:list, but I get a syntax error. Ditto when I try setting types in the parameter list on the script option. I am using the "python script" default option that comes with zope, as opposed to importing one. Any help would be gratefully appreciated. I am certain there must be some way, but I haven't been able to discover it myself, and I certainly don't want to have to start every script with a split on , Thanks Di
On Monday 17 June 2002 01:07 am, Dianne Van Dulken wrote:
Hi,
I'm finding whenever I call a python script from within a zope page (as opposed to submitting a form to a script), it assumes that every parameter is a string. This isn't always the case, in fact, it is rarely the case. I was wondering if there was anyway that I could force it to know what type it was. I am particularly interested in passing in lists.
The way I call it at the moment is like this:
<dtml-var expr="script1(var1='blah', var2=['a', 'b', 'c'])"> etc.
on zope2.5.1, i do get the necessary objects. e.g dtml-method <dtml-var standard_html_header> <h2><dtml-var title_or_id> <dtml-var document_title></h2> <p><dtml-var expr="te(a='string',b=['1','a'])"> </p> <dtml-var standard_html_footer> script python #parameters a, b return a,b gives me ('string',['1','a']) which is right hth -- http://www.kedai.com.my/ http://www.kedai.com.my/eZine http://www.zope.org/Members/kedai http://www.my-zope.org If you SMELLLL...
[Dianne Van Dulken]
I'm finding whenever I call a python script from within a zope page (as opposed to submitting a form to a script), it assumes that every parameter is a string. This isn't always the case, in fact, it is rarely the case. I was wondering if there was anyway that I could force it to know what type it was. I am particularly interested in passing in lists.
The way I call it at the moment is like this:
<dtml-var expr="script1(var1='blah', var2=['a', 'b', 'c'])"> etc.
Please explain what behavior led you to conclude that the python script is getting or handling the parameters as strings. Naturally, if you say var1='blah', you will get a string, because you explicitly said so. If you say var2=[1,2,3] you will get a list. I just tested this on my system and a list is passed as a list (Zope 2.3.3 on Win 2000). Also please say what version of Zope you are using. Zope does pass the right type of parameter and Python does understand them, so it seems likely that you are doing something you don't realize that is interfering.
I tried calling them like var1:string, var2:list, but I get a syntax error. Ditto when I try setting types in the parameter list on the script option.
Naturally, because var2:list is not python syntax.
I am using the "python script" default option that comes with zope, as opposed to importing one.
Do you mean that you have created a "python script"? Have you added the parameters in the list at the top of the script's page? Cheers, Tom P
participants (3)
-
Bakhtiar A Hamid -
Dianne Van Dulken -
Thomas B. Passin