convert #var sequence-item to integer?
Hello everyone. I'm trying to iterate over a list returned from a form using #in and the sequence-item DHTML variable to index other lists. It's the standard table of checkboxes thing to identify a group of rows to operate on. My DHTML is: <!--#in selections--> <!--#let i=sequence-item--> link_num = <!--#var "link_num[i]"--><br> link_title = <!--#var "link_title[i]"--><br> link_data = <!--#var "link_data[i]"--><br> <!--#/let--> <!--#/in--> The error I get is "sequence index must be an integer". Zope doesn't seem to be converting the sequence-item variable into an integer before looking up the value in the list. If I change sequence-item to sequence-index, everything works (except for the fact it returns the wrong data (-:). Perhaps this whole list of items with checkboxes next to them structure should be turned into a pattern, object, or HOWTO item as it seems to pop up a lot of times in the mail archive. Tim. -- Tim Potter, System Admin/Programmer "Disco Stu doesn't advertise" Advanced Computational Systems CRC, RSISE Bldg Australian National University, Canberra 0200, AUSTRALIA Ph: +61 2 62798813 Fax: +61 2 62798602
On Tue, 10 Aug 1999, Tim Potter wrote:
The error I get is "sequence index must be an integer". Zope doesn't seem to be converting the sequence-item variable into an integer Where are you coming from, that you expect a language to convert a string to an integer automatically? *wonder*
Try: _.string.atoi(i) Andreas -- Andreas Kostyrka | andreas@mtg.co.at phone: +43/1/7070750 | phone: +43/676/4091256 MTG Handelsges.m.b.H. | fax: +43/1/7065299 Raiffeisenstr. 16/9 | 2320 Zwoelfaxing AUSTRIA
Andreas Kostyrka writes:
The error I get is "sequence index must be an integer". Zope doesn't seem to be converting the sequence-item variable into an integer
Where are you coming from, that you expect a language to convert a string to an integer automatically? *wonder*
Try: _.string.atoi(i)
Are you serious? There isn't a smiley so I guess so. I think my Perl mindset may be what is confusing here. The following two statements bits of perl produce the same result: 43. $ perl -e 'print(42 + 1)' $ perl -e 'print("42" + "1")' Perl automatically converts between strings and integers as the need arises so in my mind, trying to index an array with a string makes perfect sense to a Perl programmer. Since DTML expressions are Python based and [quickly checks through my copy of Learning Python] Python seems to have a stricter typing system than Perl. I'm sure people who speak Python as a second language (-: may be similarly confused. Regards, Tim.
Andreas -- Andreas Kostyrka | andreas@mtg.co.at phone: +43/1/7070750 | phone: +43/676/4091256 MTG Handelsges.m.b.H. | fax: +43/1/7065299 Raiffeisenstr. 16/9 | 2320 Zwoelfaxing AUSTRIA
-- Tim Potter, System Admin/Programmer "Disco Stu doesn't advertise" Advanced Computational Systems CRC, RSISE Bldg Australian National University, Canberra 0200, AUSTRALIA Ph: +61 2 62798813 Fax: +61 2 62798602
Tim Potter wrote:
Andreas Kostyrka writes:
The error I get is "sequence index must be an integer". Zope doesn't seem to be converting the sequence-item variable into an integer
Where are you coming from, that you expect a language to convert a string to an integer automatically? *wonder*
Try: _.string.atoi(i)
Are you serious? There isn't a smiley so I guess so.
I think my Perl mindset may be what is confusing here. The following two statements bits of perl produce the same result: 43.
$ perl -e 'print(42 + 1)' $ perl -e 'print("42" + "1")'
As do the following: $ perl -e 'print("42 monkeys" + "1 snake")' $ perl -e 'print("43" + "Hello world")'
Perl automatically converts between strings and integers as the need arises
And even when the need does not arise, or would be downright silly. The overagressive numberification of data was the original reason I abandoned perl for Python.
so in my mind, trying to index an array with a string makes perfect sense to a Perl programmer.
I'm sure it does. ;)
Since DTML expressions are Python based and [quickly checks through my copy of Learning Python] Python seems to have a stricter typing system than Perl.
I'm sure people who speak Python as a second language (-: may be similarly confused.
It probably depends what their first language was. :) Jim -- Jim Fulton mailto:jim@digicool.com Python Powered! Technical Director (888) 344-4332 http://www.python.org Digital Creations http://www.digicool.com http://www.zope.org Under US Code Title 47, Sec.227(b)(1)(C), Sec.227(a)(2)(B) This email address may not be added to any commercial mail list with out my permission. Violation of my privacy with advertising or SPAM will result in a suit for a MINIMUM of $500 damages/incident, $1500 for repeats.
Jim Fulton wrote:
$ perl -e 'print("42 monkeys" + "1 snake")'
BTW, both perl and Python get this wrong. Perl gives 43 and Python gives "42 monkeys1 snake", when the answer is clearly "41 monkeys and 1 fat snake". Jim -- Jim Fulton mailto:jim@digicool.com Python Powered! Technical Director (888) 344-4332 http://www.python.org Digital Creations http://www.digicool.com http://www.zope.org Under US Code Title 47, Sec.227(b)(1)(C), Sec.227(a)(2)(B) This email address may not be added to any commercial mail list with out my permission. Violation of my privacy with advertising or SPAM will result in a suit for a MINIMUM of $500 damages/incident, $1500 for repeats.
At 04:35 10-8-99 , Tim Potter wrote:
Hello everyone. I'm trying to iterate over a list returned from a form using #in and the sequence-item DHTML variable to index other lists. It's the standard table of checkboxes thing to identify a group of rows to operate on. My DHTML is:
<!--#in selections--> <!--#let i=sequence-item--> link_num = <!--#var "link_num[i]"--><br> link_title = <!--#var "link_title[i]"--><br> link_data = <!--#var "link_data[i]"--><br> <!--#/let--> <!--#/in-->
The error I get is "sequence index must be an integer". Zope doesn't seem to be converting the sequence-item variable into an integer before looking up the value in the list. If I change sequence-item to sequence-index, everything works (except for the fact it returns the wrong data (-:).
If you define your checkboxes as :int:list they will be converted to a sequence of integers. -- Martijn Pieters, Web Developer | Antraciet http://www.antraciet.nl | T: +31 35 7502100 F: +31 35 7502111 | mj@antraciet.nl http://www.antraciet.nl/~mj | PGP: http://wwwkeys.nl.pgp.net:11371/pks/lookup?op=get&search=0xA8A32149 ---------------------------------------------
participants (4)
-
Andreas Kostyrka -
Jim Fulton -
Martijn Pieters -
Tim Potter