[Zope] Dictionaries in DTML
Casey Duncan
cduncan@kaivo.com
Tue, 06 Mar 2001 08:08:09 -0700
"John R. Daily" wrote:
>
> I'm perplexed by dictionary handling in DTML.
>
> >From a Python Script, I'm returning a dictionary.
>
> The Zope Book and other DTML documentation refers to a mapping
> attribute in <dtml-in>, but provides no examples, and I'm afraid I
> can't get anything to work, with or without that attribute.
>
> I've even stripped out access to the values, and still nothing works.
>
> I've created a simple Python script ("return_dict"):
> ---
> return { "foo" : "bar", "input" : "output" }
> ---
>
> And a simple DTML script:
> ---
> <dtml-in expr="return_dict()" mapping>
> foo
> </dtml-in>
> ---
>
> With or without the mapping attribute, that gives me a KeyError: 0,
> with the problem occuring in DT_In.py, in renderwob().
>
> What am I doing wrong, and moreover, once I'm doing it right, how do I
> access the values?
>
> -- --
> John R. Daily jdaily@progeny.com
> Systems Programmer Progeny Linux Systems
> Master of the ephemeral epiphany
>
The mapping option is used with a list of dictionaries. It iterates the
list and pushes the contents of each dictionary on the namespace in
turn.
To iterate a plain dictionary use:
dict.keys()
or
dict.items()
--
| Casey Duncan
| Kaivo, Inc.
| cduncan@kaivo.com
`------------------>