Hi, I need to extract some info from a file. This is two rows from what the file looks like:

....etcetc until last row:

I want to extract prob from each row in the file and put it in a new file, but I don't know how to do it. I tried to use index to find each prob, but the thing is that the last row ends with prob=0.0093. , i.e. prob=0.0093 with a dot at the end, so when I search for 'index_end' which would be semicolon it works for all lines except the last one, which is a dot.

Edited 4 Years Ago by sofia85: n/a

Still with this? :(

data = """prob=0.0093;ID=RGT430;BQRS=491;BRZ=-4.263;ID2=RT914;DRT=0.00;HRun=0;HaplotypeScore=0.2794;
....etcetc until last row:

def prob(line):
    if 'prob=' in line:
            line = line.split('prob=', 1)[1].rstrip('.')
            return float(line.split(';', 1)[0])

for line in data.splitlines():
    pr = prob(line)
    if pr is not None:

Edited 4 Years Ago by pyTony: n/a

Just test for it and eliminate the trailing period

test_text = test_text.strip()
if test_text.endswith("."):
    print test_text[:-1]
    print test_text[:-1].split("=")

Edited 4 Years Ago by woooee: n/a

This question has already been answered. Start a new discussion instead.