DTML parsing Python- tuples and lists
Hello: I wondering how/if DTML can parse Python sequence types: the list and tuple. The scenario: an external method returns a tuple full of stuff(lists and dictionaries), and I want to tear it down and format it using DTML fors and DTML ifs, but I don't see anyone talking about doing this. Any pointers would be appreciated. -andy diller
On Wed, 5 Apr 2000, Andrew Diller wrote:
The scenario: an external method returns a tuple full of stuff(lists and dictionaries), and I want to tear it down and format it using DTML fors and DTML ifs, but I don't see anyone talking about doing this.
dtml-in is the tag you want. It will happily iterate over a tuple or list (and it does something with dictionaries ('mappings'), see the mapping keyword). And of course you can pythoically manipulate your data objects inside a dtml-if expression. --RDM
On Wed, Apr 05, 2000 at 05:01:48PM -0400, R. David Murray wrote:
On Wed, 5 Apr 2000, Andrew Diller wrote:
The scenario: an external method returns a tuple full of stuff(lists and dictionaries), and I want to tear it down and format it using DTML fors and DTML ifs, but I don't see anyone talking about doing this.
dtml-in is the tag you want. It will happily iterate over a tuple or list (and it does something with dictionaries ('mappings'), see the mapping keyword). And of course you can pythoically manipulate your data objects inside a dtml-if expression.
Thanks, that's a start, but I'm still not seeing how I can tear into say, for example a tuple of lists of lists. Here is a snippet: --------------------- <dtml-let results="my_external_method(something, more, abitmore)"> <table bgcolor=lightyellow> <dtml-in results> <TR> <TD>results#<dtml-var sequence-index>,<dtml-var sequence-number> = </TD> <TD><dtml-var sequence-item></TD> <TD><dtml-var sequence-key><TD> </TR> </dtml-in> </table> </dtml-let> ----------------------- this external method returns a tuple of items, these items themselves are compsed of three items, one of which it itself a big list containing some other lists, a dictionary and some elements. The above code, if queried with info that returns a tuple of two elements- sequence-item contains the two tuples, where I think it should _only_ have the current item in the tuple. sequence-key, however, has the _first_ item of the tuple. What I am I trying to do is: (pythonic code) let RESULTS be a tuple returned by my external method for x in results: for y in x: print y[0] print y[1] for z in y[2]: print z I can't see how you address items inside the tuple that you initially have. Does someone have some examples? -andy diller
Andrew Diller wrote:
Thanks, that's a start, but I'm still not seeing how I can tear into say, for example a tuple of lists of lists.
Something like the following? <dtml-let results="([1,2,['a','b']], [2,3,['b','c']], [3,4,['c','d']])"> <dtml-in results> Indexed[0]: <dtml-var "_['sequence-item'][0]"><BR> Indexed[1]: <dtml-var "_['sequence-item'][1]"><BR> <dtml-in "_['sequence-item'][2]"> <dtml-var sequence-item><BR> </dtml-in> </dtml-in> </dtml-let> Regards, Daryl Tester
Andrew Diller wrote:
Hello: I wondering how/if DTML can parse Python sequence types: the list and tuple.
The <dtml-in> tag iterates over sequences and it is loosely analogous to a python 'for'. It is documented pretty thourougly in the DTML Programmers Guide on the Zope site. -Michel
On Sat, Apr 08, 2000 at 12:49:21PM -0700, Michel Pelletier wrote:
Andrew Diller wrote:
Hello: I wondering how/if DTML can parse Python sequence types: the list and tuple.
The <dtml-in> tag iterates over sequences and it is loosely analogous to a python 'for'.
It is documented pretty thourougly in the DTML Programmers Guide on the Zope site.
Yes, thanks. The biggest braincloud to disperse is the notion of the dtml-let and dtml-in sequence. I managed to get it working with this code: -------------- (this is taken from Amos's articles on xml.com) ------------- <dtml-let results="findHost(username,password,host,domain)"> <dtml-in results > <dtml-let X=sequence-item> <dtml-in X> <dtml-if sequence-end> <table border=3 width=70%> <TR BGCOLOR="#FFFF99"> <dtml-let Y=sequence-item> <TD width=10%> Hostname: </TD><TD> <dtml-var "Y['Hostname']"> </TD></TR> <TD > IP: </TD><TD> <dtml-var "Y['IPv4Address']"> </TD></TR> <TD > Model: </TD><TD> <dtml-var "Y['Model']"> </TD></TR> <TD > Vendor: </TD><TD> <dtml-var "Y['Vendor']"> </TD></TR> <TD > EndUser: </TD><TD> <dtml-var "Y['EndUser']"> </TD></TR> <TD > Room: </TD><TD> <dtml-var "Y['Room']"> </TD></TR> <TD > HostType: </TD><TD> <dtml-var "Y['HostType']"> </TD></TR> <TD > Contact: </TD><TD> <dtml-var "Y['DNSContact']"> </TD></TR> <TD > Remarks: </TD><TD> <dtml-var "Y['Remarks']"> </TD></TR> <TD > TTL: </TD><TD> <dtml-var "Y['TTL']"> </TD></TR> <TD > ORG: </TD><TD> <dtml-var "Y['ORG']"> </TD></TR> <TD > IP Range: </TD><TD> <dtml-var "Y['IPv4Range']"> </TD></TR> <TR><TD> - End of Record- </TD><TD> <dtml-var "Y['Hostname']"></TD> </dtml-let> </table><HR> </dtml-if> </TR> </dtml-in></dtml-let></dtml-in></dtml-let> ------------- -andy
participants (4)
-
Daryl Tester -
dillera@isc.upenn.edu -
Michel Pelletier -
R. David Murray