----- Original Message ----- From: "Andrew Hedges" <[EMAIL PROTECTED]>
To: "Jonathan" <[EMAIL PROTECTED]>
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 accomplish.


Thanks, again!

On Feb 27, 2006, at 10:05 AM, Jonathan wrote:

----- Original Message ----- From: "Andrew Hedges" <[EMAIL PROTECTED]>
To: <zope@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)">

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})">



Zope maillist  -  Zope@zope.org
**   No cross posts or HTML encoding!  **
(Related lists - http://mail.zope.org/mailman/listinfo/zope-announce
http://mail.zope.org/mailman/listinfo/zope-dev )

Reply via email to