[Zope] converting Dictionary to Result

Jonathan dev101 at magma.ca
Mon Jun 19 13:25:59 EDT 2006


You could try something like:

contents of myscript():
mydict = {'key1': 'value1', 'key2': 'value2'}
mydict2 = {'key1': 'value3', 'key2': 'value4'}

rList = []
for item in mydict.keys():
   rList.append( (item, mydict1[item]) )
for item in mydict2.keys():
   rList.append( (item, mydict2[item]) )
return rList



then, in your DTML method:

<dtml-in myscript>
  <dtml-var sequence-key>, <dtml-var sequence-item><br>
 </dtml-in>    


Jonathan



  ----- Original Message ----- 
  From: Alric Aneron 
  To: Andreas Jung ; zope at zope.org 
  Sent: Monday, June 19, 2006 12:35 PM
  Subject: Re: [Zope] converting Dictionary to Result


  Thanks,
  Here is what I'm trying to do:
  Let's say:
  contents of myscript():
  mydict = {'key1': 'value1', 'key2': 'value2'}
  mydict2 = {'key1': 'value3', 'key2': 'value4'}
  finalList = [mydict, mydict2]
  return finalList

  When I do this in a dtml-method:
  <dtml-in "myscript()">
     <dtml-var key1> <br/>
  </dtml-in>
  This will not return me this:
  value1
  value2
  It gives me a key error.
  However if I loop through a recordset, it produces proper output.
  I'd like to merge a record object and a dictionary object so I can access them like I showed you here with dtml-in - so I can loop over both of them.

  Is there a way?

  Thanks in advance guys!

  Andreas Jung <lists at zopyx.com> wrote:


    --On 19. Juni 2006 09:16:23 -0700 Alric Aneron 
    wrote:

    > Hello,
    > I have a dictionary object and a result set object (that was returned
    > from a ZSQL method). Is there any way I can merge them into one variable
    > and use them in a dtml-in statement?
    >

    result sets have a dictionaries() method and dict have an update() 
    method..everything else is one-liner-Python magic and depends on your 
    usecase.

    -aj


    -- 
    ZOPYX Ltd. & Co. KG - Charlottenstr. 37/1 - 72070 T�bingen - Germany
    Web: www.zopyx.com - Email: info at zopyx.com - Phone +49 - 7071 - 793376
    E-Publishing, Python, Zope & Plone development, Consulting





------------------------------------------------------------------------------
  Yahoo! Sports Fantasy Football '06 - Go with the leader. Start your league today! 


------------------------------------------------------------------------------


  _______________________________________________
  Zope maillist  -  Zope at zope.org
  http://mail.zope.org/mailman/listinfo/zope
  **   No cross posts or HTML encoding!  **
  (Related lists - 
   http://mail.zope.org/mailman/listinfo/zope-announce
   http://mail.zope.org/mailman/listinfo/zope-dev )
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.zope.org/pipermail/zope/attachments/20060619/6082775b/attachment.htm


More information about the Zope mailing list