I need to split a variable out into two parts. The variable looks like this: 108243-132 and I need to split it where the - is. I can do this easy enough in Perl but this Zope server happens to be on a Wintendo 2000 box and I haven't been able to get perl working correctly with Zope. Is there an easy way to split a variable with dtml? "The Zope Book" that I bought doesn't seem to cover any of this, or it does in such an obscure way that I can't find what I'm looking for. It's been a great book to start with, but I need something that's a little more in depth. I've seen a few more books on Amazon and I'm thinking about buying the Zope Bible to keep me busy until Dieter's book comes out. Does anybody have any suggestions? Rick
I need to split a variable out into two parts. The variable looks like this: 108243-132 and I need to split it where the - is. I can do this easy enough in Perl but this Zope server happens to be on a Wintendo 2000 box and I haven't been able to get perl working correctly with Zope. Is there an easy way to split a variable with dtml?
The best way is probably to use the string module. The line below (untested) should provide you with a variable in the REQUEST called 'your_split_variable_which_is_now_a_list' that is a list of the two halves of your original variable. <dtml-call "REQUEST.set('your_split_variable_which_is_now_a_list', string.split(your_variable, '-'))"> hth tim
Hi Rick, I think that something like this will work for you: <dtml-call expr="REQUEST.set('ListContainingSplitItems', _.string.split(VariableNameToSplit, '-')"> This sets a variable in the REQUEST dictionary by first calling the split function of the string module. The ListContainingSplitItems variable will contain the results of your call to split(). The "VariableNameToSplit" variable is the one that contains the "108243-132" string. Then you can iterate through your split items with <dtml-in ListContainingSplitItems> <!-- Do something useful here --> Item #<dtml-var sequence-index> is <dtml-var sequence-item> </dtml-in> Search the archives or look in your Zope book for info on "_" (the underscore), which has special meaning in Zope. I would recomend that you do this sort of thing with a Python Script instead of DTML. I think it's cleaner than the messy DTML above. Script (Python) Id = split_on_hyphen parameters VariableNameToSplit import string return string.split(VariableNameToSplit, '-') Then your dtml would look like this: <dtml-in "split_on_hyphen(VariableNameToSplit)"> <!-- Do something useful here --> Item #<dtml-var sequence-index> is <dtml-var sequence-item> </dtml-in> Hope that helps, Eric. D. Rick Anderson wrote:
I need to split a variable out into two parts. The variable looks like this: 108243-132 and I need to split it where the - is. I can do this easy enough in Perl but this Zope server happens to be on a Wintendo 2000 box and I haven't been able to get perl working correctly with Zope. Is there an easy way to split a variable with dtml?
"The Zope Book" that I bought doesn't seem to cover any of this, or it does in such an obscure way that I can't find what I'm looking for. It's been a great book to start with, but I need something that's a little more in depth. I've seen a few more books on Amazon and I'm thinking about buying the Zope Bible to keep me busy until Dieter's book comes out. Does anybody have any suggestions?
Rick
<dtml-let parts="stringVarToSplit.split('-')" part1="parts[0]" part2="parts[1]"> ... dtml stuff that may use part1 and part2... </dtml-let> ... other dtml stuff that don't need part1 or part2 anymore ... BTW: you'd better learn some basics on Python (easy) otherwise you'll need to post here 50 times a day for such problems :) In addition, nearly 99% docs on Zope scripting stuffs are based on Pyhton. ----- Original Message ----- From: "D. Rick Anderson" <ruger@comnett.net> To: <zope@zope.org> Sent: Wednesday, February 20, 2002 7:55 PM Subject: [Zope] another simple one : I need to split a variable out into two parts. The variable looks like : this: 108243-132 and I need to split it where the - is. I can do this easy : enough in Perl but this Zope server happens to be on a Wintendo 2000 box : and I haven't been able to get perl working correctly with Zope. Is there : an easy way to split a variable with dtml? : : "The Zope Book" that I bought doesn't seem to cover any of this, or it : does in such an obscure way that I can't find what I'm looking for. It's : been a great book to start with, but I need something that's a little more : in depth. I've seen a few more books on Amazon and I'm thinking about : buying the Zope Bible to keep me busy until Dieter's book comes out. Does : anybody have any suggestions? : : Rick : : :
Thanks. I really do need to learn python. I just hesitate because of the amount of time that I've put into learning and using Perl. Thanks again, Rick
<dtml-let parts="stringVarToSplit.split('-')" part1="parts[0]" part2="parts[1]">
... dtml stuff that may use part1 and part2...
</dtml-let>
... other dtml stuff that don't need part1 or part2 anymore ...
BTW: you'd better learn some basics on Python (easy) otherwise you'll need to post here 50 times a day for such problems :) In addition, nearly 99% docs on Zope scripting stuffs are based on Pyhton.
----- Original Message ----- From: "D. Rick Anderson" <ruger@comnett.net> To: <zope@zope.org> Sent: Wednesday, February 20, 2002 7:55 PM Subject: [Zope] another simple one
: I need to split a variable out into two parts. The variable looks like : this: 108243-132 and I need to split it where the - is. I can do this easy : enough in Perl but this Zope server happens to be on a Wintendo 2000 box : and I haven't been able to get perl working correctly with Zope. Is there : an easy way to split a variable with dtml? : : "The Zope Book" that I bought doesn't seem to cover any of this, or it : does in such an obscure way that I can't find what I'm looking for. It's : been a great book to start with, but I need something that's a little more : in depth. I've seen a few more books on Amazon and I'm thinking about : buying the Zope Bible to keep me busy until Dieter's book comes out. Does : anybody have any suggestions? : : Rick : : :
participants (4)
-
D. Rick Anderson -
Eric Walstad -
Gilles Lenfant -
Tim Hicks