help with looping, re.search, multiple indexing

Lance Hoffmeyer lance at augustmail.com
Fri Feb 16 16:58:13 EST 2007


Hey all,

How do I add another index inside a re.search?

I want to add
for j in [96,97,98,99]
    BASE = re.search ...
    sh.Cells97...
    for i ....

so that the Table 96 within the re.search(s) becomes Table 96, Table 97, Table 98, Table 99
but don't know how to add a second index within the re.search since I already have %char
in match = re.search ... " %char, neuro ...


VAR=[]
BASE = re.search("Table 96.*?BASE.*?\d(.*?)\n", neuro, re.S ).group(1).split()[1]
sh.Cells(7,lastcol+1).Value = BASE

for i, char in enumerate(["RECEIVED E", "PARTICIPATED    "]):
	match = re.search(r"Table 96.*?%s.*?\n.*?\d(.*?)\n.*?" %char ,  neuro, re.S )
	if match:
	    VAR = match.group(1).split()[1]
	else:
	    VAR = 0
	if VAR=="-": VAR = 0
	VAR = even_odd_round(float(str(VAR)))	
	VAR = float(str(VAR))/100
	sh.Cells(i+8,lastcol+1).Value = VAR
sh.Cells(10,lastcol+1).Value= sh.Cells(9,lastcol+1).Value
sh.Cells(9,lastcol+1).Value = sh.Cells(8,lastcol+1).Value - sh.Cells(10,lastcol+1).Value



VAR=[]
BASE = re.search("Table 97.*?BASE.*?\d(.*?)\n", neuro, re.S ).group(1).split()[1]
sh.Cells(11,lastcol+1).Value = BASE
for i, char in enumerate(["RECEIVED E", "PARTICIPATED    "]):
	match = re.search(r"Table 97.*?%s.*?\n.*?\d(.*?)\n.*?" %char , neuro, re.S )
	if match:
	    VAR = match.group(1).split()[1]
	else:
	    VAR = 0
	if VAR=="-": VAR = 0
	VAR = even_odd_round(float(str(VAR)))	
	VAR = float(str(VAR))/100
	sh.Cells(i+12,lastcol+1).Value = VAR

sh.Cells(14,lastcol+1).Value= sh.Cells(13,lastcol+1).Value
sh.Cells(13,lastcol+1).Value = sh.Cells(12,lastcol+1).Value - sh.Cells(14,lastcol+1).Value






More information about the Python-list mailing list