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
Hi John, <dtml-in ... > wants a sequence type.. the 'mapping' is about the elements of the sequence. try: <dtml-let foo="[{'a':'b', 'c':'d'}]"> <dtml-in foo mapping> <dtml-var a> </dtml-in> </dtml-let> take care, -steve
"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 `------------------>
participants (3)
-
Casey Duncan -
John R. Daily -
Steve Spicklemire