[Zope] Clarification of a list of lists as a parameter to a python script.

Rudi Wurm net_seeker@web.de
Sun, 14 Apr 2002 07:51:48 +0200


On Sunday 14 April 2002 05:16, you wrote:
>
> If so, what is the correct way of passing a list of lists as a parameter
> to a python script ?  I have the following example:
>
> The DTML Document:
>
> <form method="POST" action="myscript">
> Data:
> <input type=text name="XX:list" size=50 >
> <input type="submit" value="ASIGNAR"></td>
> </form>
>
> The myscript python script with "XX" as the parameter
>
> print XX
> XX.sort()
> print XX
> if same_type(XX,[]):
>    print "It is a list"
> return printed
>
> What is put into the form ( a list of lists) is:
>
> [['c','b','a'],['a','b','c'],['a','a','d']]

sorry, but you put in a string, which is converted to ONE list due to the 
:list suffix to your name-attribut

> What I get  from the script is:
>
> ["[['c','b','a'],['a','b','c'],['a','a','d']]"]
> ["[['c','b','a'],['a','b','c'],['a','a','d']]"]
> It is a list

of course, ONE list which contents your string

> Which is a list (indeed) BUT with only one element as it -somehow- gets
> surrounded by quotes, that is it is NOT a "list of lists" but a list
> with one string element.
>
> I'd expect to get the same list back, then the sorted lists within the
> main list and later on I could reference the elements with something
> like XX[sublistnum][elementnum] kind of construction.

why not enter the lists in the input-field seperated by one special-char, for 
example | and the elements of the lists seperated by commas,
and then split the string in yout script by | and then by comma , and 
construct your lists by hand ?

p = 'a,b,c|c,b,a|a,a,d' <- your entered string in input field, no conversion 
to list, passes to python-script as string, then in script:
# p as parameter with string
 l  = []
 for si in p.split('|'):
  l.append(si.split(','))
 return l

it should also be possible to convert the '[['a','b','c'],....] syntax, with 
a bit more code.

> Any ideas on how to overcome this issue.?  The idea is NOT to modify
> already working python routines -except for the printed variable and
> security stuff whenever necessary-, just to Zope-fy the application if
> you know what i mean.

ok, to modify your existing scripts less as possible, put the conversion in a 
seperate script and call it with your string as parameter and put the result, 
the listlist, to your existing script, like in dtml with
<dtml-call 
expr="your_old_routine(conversion_routine(parameter_from_inputfield))">

> Well, any comments are welcome. Thanks in advance for your assistance.

dunno if it helps, but ...

> Felipe

Torsten Kühnel