problem with split
goyatlah
Sat Oct 7 01:27:41 EDT 2006
Think you need a regex like this: regex =
r"\s*instr\s+([0-9]+)\s*(;.*)?"
Then:
import re
test = re.compile(regex)
testing is done as follows:
res = test.match(mystring)
if res:
number = res.group(1) # always a string consisting of decimals
comment = res.group(2) # string starting with ; or None
it might be necessary to have the instr part of the regex as follows
[iI][nN][sS][tT][rR] to handle things like Instr or INSTR.
Hope this helps
Dolf
On 6 Oct 2006 21:07:43 -0700, "Eric_Dexter at msn.com"
<Eric_Dexter at msn.com> wrote:
>apologies if I annoy and for spacing (google)
>
>
>
>def csdInstrumentList(from_file):
> "Returns a list of .csd instruments and any comment lines after the
>instrument"
> infile = open(from_file, 'r')
> temp_number = 0
> for line in infile:
> if 'instr' in line:
> s = re.split(r' +',line,3)
> instr_number = s[1]
> return instr_number
>
>I am coming pretty close to what I want with variations on theis but I
>cant seem to
>get 3 lines with the split and instr_number[array] = s[1] seems to give
>me an error.
>the data from the line I am trying to split in three would look like
>this
>
> instr 83 ;comment would be here
>
>I want comment returned in an array and instr_number returned in an
>array.
More information about the Python-list
mailing list