[Zope] Convert Help

Chris Meyers chris@hddesign.com
Tue, 26 Feb 2002 12:21:31 -0600


On Tue, Feb 26, 2002 at 12:49:15PM -0500, Todd Loomis wrote:
> Matt:
> 
> Thanks, I'm getting the results ['1', '2', '3'] but I can't get them to 
> pull out by them selfs. Every time i use them I get ['1', '2', '3'] instead of
> 1
> 2
> 3
> which I need to do? So my ? is how do i use this list string to give 
> something other than ['1', '2', '3']?
> 
> Todd

What are you trying to do with these results, and where are they coming from (ZSQL, form, etc)? That may help with determinig how you can get them out individually instead of as a list. Even if that isn't possible, you should still be able to loop through the list pulling out each item and then do stuff with it. In a python script you could do something like this:

for i in resultList:
  id = 1
  option = i
  #you could also use option = int(i)
  #if you want to make sure that i is an integer
  
  #do stuf with option here
#do other stuff here

You can do this in DTML or as a Page Template as well, but that isn't recommended if you are doing complex things with the results. If you are just doing simple stuff you could do a page template like this:

<html>
<body>
<span tal:repeat="item python:scriptToGetYourList()">
  <!--That gets your list ['1','2','3'] and loops through it-->
  <div tal:content="item">Print item</div>
  <!--That will print out each item in the list one at a time-->
  <do something with item here>
</span>
</body>
</html>

Hope that helps
Chris

> 
> At 12:37 PM 2/26/2002 -0500, you wrote:
> >Todd Loomis wrote:
> >
> >>AJ
> >>
> >>Well then how do I convert a list into separate strings
> >>
> >>Todd
> >
> >
> >I think we're having difficulty establishing the context of your question, 
> >since [ 'a', 'b', 'c' ] IS a list of strings.  So, there isnt any 
> >conversion involved.
> >
> >If, in Python I had the following
> >
> >    list = [ 'one', 'two', 'three']
> >
> >I could print out each element as such:
> >
> >    for e in list: print e
> >
> >and out would print
> >
> >    one
> >    two
> >    three
> >
> >So what I am thinking is that you would be well served visiting the python 
> >tutorial at www.python.org to get details about the grammar operators.
> >
> >--
> >Matt Kromer
> >Zope Corporation  http://www.zope.com/