Hi, I'm storing a selection of a user to a database as string. This selection is a multiple selection from a select box and is outputted as a list. Now I want to iterate over this list (after retrieving it from the database), but how can I do this? How can I tell Zope that the string is actually a list? How can I typecast in Zope? Thanks, Tom.
If you want to put a string into a list you can use <dtml-var "_.string.split('a|b', '|')"> to split a string up. What database are you using and what are actually getting back? ----- Original Message ----- From: "Tom Deprez" <tom.deprez@uz.kuleuven.ac.be> To: <zope@zope.org> Sent: Tuesday, October 03, 2000 9:15 AM Subject: [Zope] List
Hi,
I'm storing a selection of a user to a database as string. This selection is a multiple selection from a select box and is outputted as a list. Now I want to iterate over this list (after retrieving it from the database), but how can I do this? How can I tell Zope that the string is actually a list? How can I typecast in Zope?
Thanks, Tom.
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
Tom Deprez wrote:
Hi,
I'm storing a selection of a user to a database as string. This selection is a multiple selection from a select box and is outputted as a list. Now I want to iterate over this list (after retrieving it from the database), but how can I do this? How can I tell Zope that the string is actually a list? How can I typecast in Zope?
Use a python or external method to make a list from your string. I am supposing you are storing a string representation of the list that looks like: "['fred', 'bob', 'mary']" Get rid of any punctuation you do not want with (e.g.) theString = string.replace(theString, '[', ' ') (Yes, there are more efficient ways to do this!) Then, once you have a space-delimited list of items, you may use theList = string.split(theString) which will make a list of the words in the string. Return theList. -- Jim Washington
I'm storing a selection of a user to a database as string. This selection is a multiple selection from a select box and is outputted as a list. Now I want to iterate over this list (after retrieving it from the database), but how can I do this? How can I tell Zope that the string is actually a list? How can I typecast in Zope?
<dtml-call "list(something)">, but that won't work in this case as you'll get a resultant [something,]
Use a python or external method to make a list from your string. I am supposing you are storing a string representation of the list that looks like:
"['fred', 'bob', 'mary']"
Get rid of any punctuation you do not want with (e.g.)
theString = string.replace(theString, '[', ' ')
(Yes, there are more efficient ways to do this!)
Then, once you have a space-delimited list of items, you may use
theList = string.split(theString)
which will make a list of the words in the string. Return theList.
a python/external method is more elegant, but if you want this can be done in the same way from DTML: <dtml-call "REQUEST.set(theString, _.string.replace(theString, '[', ' '))"> <dtml-call "REQUEST.set(theList, _.string.split(theString))"> or using dtml-let But whether all this works depends much on what your database returns. Rik
Hi all, Thanks for the lots of correct answers. With a small modification (looking up several python docs :-) ) all things worked! Thanks in advance, Tom. At 13:06 03/10/2000 -0400, you wrote:
Tom Deprez wrote:
Hi,
I'm storing a selection of a user to a database as string. This selection is a multiple selection from a select box and is outputted as a list. Now I want to iterate over this list (after retrieving it from the database), but how can I do this? How can I tell Zope that the string is actually a list? How can I typecast in Zope?
Use a python or external method to make a list from your string. I am supposing you are storing a string representation of the list that looks like:
"['fred', 'bob', 'mary']"
Get rid of any punctuation you do not want with (e.g.)
theString = string.replace(theString, '[', ' ')
(Yes, there are more efficient ways to do this!)
Then, once you have a space-delimited list of items, you may use
theList = string.split(theString)
which will make a list of the words in the string. Return theList.
-- Jim Washington
participants (4)
-
Andy McKay -
Jim Washington -
Rik Hoekstra -
Tom Deprez