Best Zope way to split a textfield on 2000 char increments
Hi, I just realized I need to split a potentially pretty long textfield input from a web form into 2000 character chunks, for input into a database. I see a lot of string functions in DTML, but none that looks like it will do this.. I'm hoping to use this as a workaround for the seeming lack of LONG text field support in the Oracle DA. (please correct me if I'm wrong on this..but I cant seem to get it to work..) I'm using Oracle 7.3 Thanks.. Chris
Chris Beaumont wrote:
Hi,
I just realized I need to split a potentially pretty long textfield input from a web form into 2000 character chunks, for input into a database. I see a lot of string functions in DTML, but none that looks like it will do this..
Use a Python Script: <params>yourstring</params> offset = 0 list=[] while offset + 2000 < len(yourstring): list.append(yourstring[:2000]) offset = offset + 2000 list.append(yourstring[offset:]) return list then you can do: <dtml-in yourexternalmethod> ...with the 2000 char chunks. Well, hope this helps. I'm sure there's at least one off-by-one bug in the above. It'd be a lot easier to do if regular expressions were available in python scripts: return re.findall('.{0,2000}',yourstring) ...but sadly we're not allowed to use regular expressions in pythno scripts in case we break something :-(( cheers, Chris
I just realized I need to split a potentially pretty long textfield input from a web form into 2000 character chunks, for input into a database. I see a lot of string functions in DTML, but none that looks like it will do this..
string slices. somestring[:1999] is the first 2000 characters of somestring.
On Fri, 15 Dec 2000, Steve Drees wrote:
somestring[:1999] is the first 2000 characters of somestring.
Not to be a poseur but: somestring[:1999] is the first 1999 characters of somestring, because in Python indices begin at 0, e.g.: a="0123" print a[:3] gives "012" which are the first 3 characters from a. bye, Jerome Alet
Jerome Alet wrote:
On Fri, 15 Dec 2000, Steve Drees wrote:
somestring[:1999] is the first 2000 characters of somestring.
Not to be a poseur but:
me either ;^)=
somestring[:1999] is the first 1999 characters of somestring, because in Python indices begin at 0, e.g.:
Actually, it is because the number 1999 refers to the the spot *inbetween* 1998 and 1999. Basically, in a list of '0,1,2,3', [0] is the first 'comma', and [1] the second, and so on. Counting that way shows that you never include the 1999 (or the three in your example. It isn't that indices start at zero, it is due to the counting being done on the seperator, not the item in the list.
a="0123" print a[:3] gives "012" which are the first 3 characters from a.
Right, because 'a' is being treated as [0,1,2,3], and you are saying "give me everything up to the third comma". :) yes-I-am-nitpicking-ly y'rs Bill Anderson
Bill Anderson wrote:
Jerome Alet wrote:
On Fri, 15 Dec 2000, Steve Drees wrote:
somestring[:1999] is the first 2000 characters of somestring.
Not to be a poseur but:
me either ;^)=
somestring[:1999] is the first 1999 characters of somestring, because in Python indices begin at 0, e.g.:
Actually, it is because the number 1999 refers to the the spot *inbetween* 1998 and 1999. Basically, in a list of '0,1,2,3', [0] is
Oops... I meant to write: ...before the first...
the first 'comma', and [1] the second, and so on. Counting that way shows that you never include the 1999 (or the three in your example. It isn't that indices start at zero, it is due to the counting being done on the seperator, not the item in the list.
Bill
participants (5)
-
Bill Anderson -
Chris Beaumont -
Chris Withers -
Jerome Alet -
Steve Drees