[Zope] string to list?

Dieter Maurer dieter@handshake.de
Mon, 18 Sep 2000 23:53:02 +0200 (CEST)


Nitesh Dhanjani writes:
 > 
 > Hello,
 > 
 > I have a Z SQL method which returns me a string like {{"a"},{"b"},{"c"}}
 > 
 > Is there anyway I can write a dtml-in loop to pick out each element from
 > the string? I want to be able to do something like:
 > 
 > <dtml-in my_zsql_method_which_returns_a_string>
 > <dtml-var element>,
 > </dtml-in>
 > 
 > and that should give me "a,b,c".
You are sure, the string always has this format?

Then there is a solution, though an external method might be better:

	<dtml-let result=sql_method
	          strip_outer_chars="result[3:-3]"
		  split="_.string.split(strip_outer_chars,'\x22},{\x22')"
		  rejoin="_.string.join(split,',')"
        >
	  <dtml-var rejoin> <!-- your a,b,c -->
	</dtml-let>


Dieter