[Zope] Dynamic dictionary keys?

Jonathan dev101 at magma.ca
Mon Feb 27 12:42:23 EST 2006

----- Original Message ----- 
From: "Andrew Hedges" <andrew at clearwired.com>
To: "Jonathan" <dev101 at magma.ca>
Sent: Monday, February 27, 2006 12:14 PM
Subject: Re: [Zope] Dynamic dictionary keys?

> Thanks, much, Jonathan!  We're moving to Zope 3 on the next version  of 
> our software, but what I'm working on is part of the last version,  which 
> is all DTML.  I appreciate your response!  It works, though,  there was a 
> small error in what you sent:
>    <dtml-call "eventsDict.update({calstart:id})">

There are various forms, all of which are correct, and it depends upon what 
you are trying to achieve:

<dtml-call "eventsDict.update({calstart:id})">

The above format takes two variables, one called calstart and one called id. 
The value contained within the variable calstart is used as the 'key' and 
the contents of id are used as the 'value'

<dtml-call "eventsDict.update({'calstart':id})">

The above format takes one 'hard-coded' key value 'calstart' and one 
variable id for the value

<dtml-call "eventsDict.update({'calstart':'id'})">

The above format takes a 'hard-coded' key value 'calstart' and a hard-coded 
value 'id'.

None of the above are 'wrong', it just a matter of what you are trying to 


> Thanks, again!
> -Andrew
> On Feb 27, 2006, at 10:05 AM, Jonathan wrote:
>> ----- Original Message ----- From: "Andrew Hedges" 
>> <andrew at clearwired.com>
>> To: <zope at zope.org>
>> Sent: Monday, February 27, 2006 11:56 AM
>> Subject: [Zope] Dynamic dictionary keys?
>>> Allow me to preface this by saying I am a complete newbie to Zope  (I 
>>> prefer to think of it as beginner's mind...).  What I am  attempting  to 
>>> do is dynamically add items to a dictionary, but  Zope complains 
>>> "keyword can't be an expression".  Here's the  reduced case of my code:
>>> <dtml-let eventsDict="{}">
>>>    <dtml-let calstart="somestring">
>>>       <dtml-call "REQUEST.set(eventsDict[calstart]=id)">
>>>    </dtml-let>
>>> </dtml-let>
>> It is much easier in python script, but if you really want to use  dtml:
>> <dtml-call "REQUEST.set('eventsDict', {})">
>> <dtml-call "eventsDict.update({'calstart' : id})">
>> hth
>> Jonathan

More information about the Zope mailing list