passing lists as function parameters
Maybe I am really missing something here, but for some time, I have been trying to figure out why when I pass a list to a python script, it becomes a sequence of characters. When I duplicate the process within the interpreter, it works as I expect it to. An example to demonstrate what I am talking about: Interpreter test-
listDef = [1,2,3,4,5] def foo(x): ... for member in x: .... print member ... foo(listDef) 1 2 3 4 5
In Zope, if I create the equivalent of the foo function in a python script, passing a list in the parameter field, I get the following: 1 , 2 , 3 , 4 , 5 Or if I test the script with the following value for the parameter - [1,2,3,4,5] - I get: [ 1 , 2 , 3 , 4 , 5 , ] so ... len(theList) returns a value that represents the count of all characters in the list definition - not the number of items in the list. Any enlightenment here would be greatly appreciated. I hesitate to call 'BUG' cause it might be me that is 'buggy'... TIA Eric
We'll need to see your 'equivalent' python script and how you call it. Lists work fine in python scripts but there is sometimes voodoo in calling said scripts or getting results back from them.
-----Original Message----- From: zope-admin@zope.org [mailto:zope-admin@zope.org]On Behalf Of Eric Roby Sent: Friday, November 08, 2002 4:33 AM To: zope@zope.org Subject: [Zope] passing lists as function parameters
Maybe I am really missing something here, but for some time, I have been trying to figure out why when I pass a list to a python script, it becomes a sequence of characters. When I duplicate the process within the interpreter, it works as I expect it to. An example to demonstrate what I am talking about:
Interpreter test-
listDef = [1,2,3,4,5] def foo(x): ... for member in x: .... print member ... foo(listDef) 1 2 3 4 5
In Zope, if I create the equivalent of the foo function in a python script, passing a list in the parameter field, I get the following: 1 , 2 , 3 , 4 , 5
Or if I test the script with the following value for the parameter - [1,2,3,4,5] - I get: [ 1 , 2 , 3 , 4 , 5 , ] so ... len(theList) returns a value that represents the count of all characters in the list definition - not the number of items in the list.
Any enlightenment here would be greatly appreciated. I hesitate to call 'BUG' cause it might be me that is 'buggy'...
TIA
Eric
If you are using the test tab in the mangage scripts section, AFAIK the arguments are sent in as part of the REQUEST, and in REQUEST unless the form variable names have a :list at the end, Zope will not treat them as lists. In general when you use the test tab I have observed that the arguments are passed in as strings. While testing Python Scripts that take in lists or other such stuff, I usually test them using a DTML method or such. HTH AM Eric Roby wrote:
Maybe I am really missing something here, but for some time, I have been trying to figure out why when I pass a list to a python script, it becomes a sequence of characters. When I duplicate the process within the interpreter, it works as I expect it to. An example to demonstrate what I am talking about:
Interpreter test-
listDef = [1,2,3,4,5] def foo(x):
... for member in x: .... print member ...
foo(listDef)
1 2 3 4 5
In Zope, if I create the equivalent of the foo function in a python script, passing a list in the parameter field, I get the following: 1 , 2 , 3 , 4 , 5
Or if I test the script with the following value for the parameter - [1,2,3,4,5] - I get: [ 1 , 2 , 3 , 4 , 5 , ] so ... len(theList) returns a value that represents the count of all characters in the list definition - not the number of items in the list.
Any enlightenment here would be greatly appreciated. I hesitate to call 'BUG' cause it might be me that is 'buggy'...
TIA
Eric
_______________________________________________ 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 )
-- ================================================================== Aseem Mohanty Neurobehavioral Systems Inc, 828 San Pablo Ave, Albany, CA 94706 (R) 510 7696011 (M) 510 3014871 (O) 510 5279231 ================================================================== "I saw `cout' being shifted "Hello world" times to the left and stopped right there!!" -- Steve Gonedes ==================================================================
Eric Roby writes:
Maybe I am really missing something here, but for some time, I have been trying to figure out why when I pass a list to a python script, it becomes a sequence of characters. When I duplicate the process within the interpreter, it works as I expect it to. An example to demonstrate what I am talking about:
Interpreter test-
listDef = [1,2,3,4,5] def foo(x): ... for member in x: .... print member ... foo(listDef) 1 2 3 4 5
In Zope, if I create the equivalent of the foo function in a python script, passing a list in the parameter field, I get the following: 1 , 2 , 3 , 4 , 5 You do not pass a list here but a string and you iterate over the bytes of the string.
When you would pass a true list and not just a string that looks like (the string representation of) a list, then it would work as you expect. Dieter
participants (4)
-
AM -
Charlie Reiman -
Dieter Maurer -
Eric Roby