[Zope-dev] #in on a list of dictionaries, how do I iterate over keys?

Brad Clements bkc@murkworks.com
Tue, 11 May 1999 14:21:58 -0400


I have an external function that returns a list of dictionaries.

I want to iterate over the list, then iterate over each key/value pair in the 
dictionary so I can create a table of key:value

This works:

<!--#in "MyFunction()"-->
<!--#var sequence-item-->
<!--#/in-->

In this case, sequence-item shows as a dictionary. Now I need to 
iterate over that sequence item, but  no matter how I try, I can't do it. I've 
tried saving the contents of sequence-item in REQUEST, then using #in 
on that variable, no-go..

I guess I'm looking for something like this:

<!--#in "MyFunction()"-->
<!--#in sequence-item-->
<!--#var sequence-key--> = <!--#var sequence-key-->
<!--#/in-->
<!--#/in-->


So if MyFunction() returns [{name:'fred',zip:123},{name:'bill',zip:255}]

then I want to see

name = fred
zip = 123
name = bill
zip = 255

If I use

<!--#in "MyFunction()" mapping-->

then I can use <!--#var name-->

But then I have to manually list all the keys and I have to know them in 
advance.

Ideas welcome.. thanks



Brad Clements,                bkc@murkworks.com   (315)268-1000
http://www.murkworks.com                          (315)268-9812 Fax
netmeeting: ils://ils.murkworks.com               ICQ: 14856937