Newbie question about Re
mcfletch at vrtelecom.com
Tue Aug 24 16:58:41 CEST 1999
Well, here's my take on a "better way"... I don't see why you would want to
use the RE module when you aren't doing any pattern matching...
def splitlen( instring, desiredlength):
temp = 
current = 0
lenstr = len( instring)
while current < lenstr:
newcurrent = current+desiredlength
temp.append( instring[current:newcurrent] )
current = newcurrent
I haven't even tested this for correctness, but I think it's close to
Hope this helps,
From: python-list-request at cwi.nl [mailto:python-list-request at cwi.nl]On
Behalf Of MB
Sent: August 24, 1999 9:05 AM
To: python-list at cwi.nl
Subject: Newbie question about Re
I just want to split a string of n x (p characters) into a list of
p_length strings using the Re module
Example: Assume p=5 the string '12345ABCDE12345IJKLM' must be split in
The way I find is to make a replace before splitting:
# I use ### as separator
['12345', 'ABCDE', '12345', 'IJKLM', '']
# And I have to remove the trailing ''
But I don't like this too much.
Is there a better way?
More information about the Python-list