Help with unconsistent behavior of parameter passing to Python Scripts.
Hello all: Having the following Python script: if same_type(RR,[]): return "It is a list" if same_type(RR,'abcd'): return "it is a string" If I use on the parameter's list (sme scrren where the Python script is edited) the value: RR=[['04-03-2001','0900','MEX','PBA','0300','N'],['04-03-2001','1100','MTY','NLD','0300','N'],['04-03-2001','1600','NLD','MTY','0300','N']] and proceed to TEST the script with the test tab, I am asked for the value of RR (two fields), if I give nothing, then the message "It is a list" is printed, as expected. But, if the same thing, (except the initial RR=) is fed into the values field at the test page, then the result comes as a "string", which is NOT the intended effect. This is just a brief test to find out what is going on, the goal is to be able to feed into a Python script, a list of lists that the script will process and output another list of lists. We have been unable to obtain this as the scripts always ends getting a string instead of the wanted list (of lists). Can anyone be so kind to explain the behavior of this ? And, to provide some samples on how to make this work correctly ? By the way, we started with a perfectly working *.py program file , converting it into a script which behave on a similar way to the test just shown. Thanks in advance for your help. Edward. Piensa Tech.
febb writes:
Having the following Python script:
if same_type(RR,[]): return "It is a list" if same_type(RR,'abcd'): return "it is a string"
... calling "Test" with parameter value "[...]" returns "is a string"... I think, this is correct behaviour:
Python is not statically typed. The same name can be bound to different types over time. The fact, that your argument has a list as default value does not mean, that all passed in values will be lists. The parameters passed with any Web request *ARE* all strings in the first place. Zope uses various ":XXX" suffixes to the parameter names to control how these strings are converted into other datatype (see e.g. <http://www.dieter.handshake.de/pyprojects/zope/book/chap3.html> ). But the "Test" interface of "PythonScripts" does not support these conversion suffixes. I agree, this is a limitation, but not inconsistent... Dieter
Seems the problem may be better expressed as having a python script that when run (within python), can be fed with a list of lists, like: RR=[ ['04-03-2001','0900','MEX','PBA','0300','N'], ['04-03-2001','1100','MTY','NLD','0300','N'], ['04-03-2001','1600','NLD','MTY','0300','N'], ['04-03-2001','1800','MTY','NLD','0300','N'], ['04-03-2001','1400','MTY','NLD','0300','N'], ['04-03-2001','1000','NLD','MTY','0300','N'], ['04-03-2001','0800','MTY','NLD','0300','N'], ['04-03-2001','0900','NLD','MTY','0300','N'], ['04-03-2001','1000','MTY','NLD','0300','N'], ['04-03-2001','1300','NLD','MTY','0300','N'], ['04-03-2001','1200','PBA','MEX','0300','N'], ['04-03-2001','0930','NLD','MTY','0300','N'], ['04-03-2001','0800','MTY','NLD','0300','N'], ['04-03-2001','0900','MTY','NLD','0300','N'], ['04-03-2001','1100','NLD','MTY','0300','N'] ] If this is given as input to a simple script that say, it only sorts the list of lists for i in range(len(RR)): print RR[i] RR.sort() print "---------------------------------" for i in range(len(RR)): print RR[i] It works fine. But, when this is made a python script, it does not work. When RR is typed into (or pasted into) the form: <form method="POST" action="mypythonscript"> <input type=text name="RR:list"> </form> The script at mypythonscript indeed receives a list, but it does not know that the elements of this list are in turn other lists. The questions that come up then are: 1.- Why it works with plain python and does not with Zope 2.- How to make it work with zope by indicating that the passed value is a "list of lists" Hope this clears things a bit. Any help is greatly appreciated. Thanks in advance. Felipe Barousse On Fri, 2002-04-12 at 14:48, Dieter Maurer wrote:
febb writes:
Having the following Python script:
if same_type(RR,[]): if same_type(RR,'abcd'): return "it is a string"
... calling "Test" with parameter value "[...]" returns "is a string"... I think, this is correct behaviour:
Python is not statically typed. The same name can be bound to different types over time.
The fact, that your argument has a list as default value does not mean, that all passed in values will be lists.
The parameters passed with any Web request *ARE* all strings in the first place. Zope uses various ":XXX" suffixes to the parameter names to control how these strings are converted into other datatype (see e.g.
<http://www.dieter.handshake.de/pyprojects/zope/book/chap3.html>
). But the "Test" interface of "PythonScripts" does not support these conversion suffixes.
I agree, this is a limitation, but not inconsistent...
Dieter
On Saturday 13 April 2002 00:40, you wrote: ...
The script at mypythonscript indeed receives a list, but it does not know that the elements of this list are in turn other lists. The questions that come up then are: < 1.- Why it works with plain python and does not with Zope 2.- How to make it work with zope by indicating that the passed value is a "list of lists"
Hope this clears things a bit. Any help is greatly appreciated. Thanks in advance.
ok, i did some low-level testing for you, hope it helps abit. one zope-python-script: # script param-call in pyth-folder # ... some zope-init stuff ... # no parameters return context.pyth.param_test([0],[[1],[0]]) which calls this one: # script param-test in pyth-folder # ... some zope-init stuff ... # parameters list and listlist l = [] return str(same_type(l, list)) + str(same_type(l, listlist[0])) result is 11, list and first element of listlist are both of type "list". so python inside zope works like expected. your problem can ONLY be in parameter-passing to your script. You maybe should leave the parameters as strings and convert them to list by hand in your script or so.
Felipe Barousse
Torsten
Dieter Maurer wrote:
). But the "Test" interface of "PythonScripts" does not support these conversion suffixes.
It does (with some limitation:e.g. if you want a list you can pass just a one element list) Bye -- Luca Olivetti
participants (5)
-
Dieter Maurer -
febb -
Felipe E. Barousse B. -
Luca Olivetti -
Rudi Wurm