Hi, I would like to know if someone can help me with this one. I need to loop by a set of variables so I can insert then into my database. I started looking at the following example: <dtml-in "16,21,3,49"> item# <dtml-var sequence-index>,<dtml-var sequence-number> = <dtml-var sequence-item> </dtml-in> and it's output item# 0,1 = 16 item# 1,2 = 21 item# 2,3 = 3 item# 3,4 = 49 So.. I changed the <dtml-in> tag by repalcing the fixed values with one of my variables. It did worg fine : <dtml-in description> <dtml-var sequence-item> </dtml-in> The problem is that I need more than one column per line of data E.G. <dtml-in (ordnumber,description)> <dtm-var sequence-item> </dtml-in> output 01 Freight 02 Delivery Is there a way I can do that ? thanks, Flavio --- Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.458 / Virus Database: 257 - Release Date: 2/24/2003
<dtml-in "[{'ordno': 1, 'order': 'tacos'}, {'ordno': 2, 'order': 'fries'}]"> <dtml-var expr="_['sequence-item']['ordno']" fmt="%02d"><dtml-var expr="_['sequence-item']['order']" fmt="%8s"> </dtml-in> or Python: output = '' records = [{'ordno': 1, 'order': 'tacos'}, {'ordno': 2, 'order': 'fries'}] for record in records: output = '%s%02d%8s\n' % (output, record['ordno'], record['order']) return output Flavio wrote:
Hi,
I would like to know if someone can help me with this one. I need to loop by a set of variables so I can insert then into my database. I started looking at the following example:
<dtml-in "16,21,3,49"> item# <dtml-var sequence-index>,<dtml-var sequence-number> = <dtml-var sequence-item> </dtml-in>
and it's output
item# 0,1 = 16 item# 1,2 = 21 item# 2,3 = 3 item# 3,4 = 49
So.. I changed the <dtml-in> tag by repalcing the fixed values with one of my variables. It did worg fine :
<dtml-in description> <dtml-var sequence-item> </dtml-in>
The problem is that I need more than one column per line of data E.G.
<dtml-in (ordnumber,description)> <dtm-var sequence-item> </dtml-in>
output
01 Freight 02 Delivery
Is there a way I can do that ?
thanks,
Flavio
---
Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.458 / Virus Database: 257 - Release Date: 2/24/2003
_______________________________________________ Zope maillist - Zope@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 )
The problem is that I need more than one column per line of data E.G.
<dtml-in (ordnumber,description)> <dtm-var sequence-item> </dtml-in>
output
01 Freight 02 Delivery
The "ordnumber" sounds like something you could provide in the SQL; even though the data does not exist in the table. If you don't like that approach, and if you need it as simple as your example, then just use string.zfill
import string string.zfill(4, 2) '04' string.zfill(44, 2) '44'
I.e. like this: <dtml-var "_.string.zfill(_['sequence-number'], 2)">
Is there a way I can do that ?
thanks,
Flavio
---
Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.458 / Virus Database: 257 - Release Date: 2/24/2003
_______________________________________________ Zope maillist - Zope@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 )
Flavio wrote at 2003-2-24 16:04 -0500:
.... <dtml-in (ordnumber,description)> <dtm-var sequence-item> </dtml-in>
output
01 Freight 02 Delivery
You can use "map(None,l1,l2)" to "transpose" the two lists: If "l1" is "x1,x2,..." and "l2" is "y1,y2,...", then "map(None,l1,l2)" is "(x1,y1), (x2,y2), ...". You can then iterate over the result: "sequence-key" will be the element from the first and "sequence-item" the from the second list. Dieter
participants (4)
-
Chris Beaven -
Dieter Maurer -
Flavio -
Peter Bengtsson