470,648 Members | 1,691 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,648 developers. It's quick & easy.

help with looping, re.search, multiple indexing

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

Feb 16 '07 #1
1 1163
Lance Hoffmeyer wrote:
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 ...
You can make format strings with an arbitrary number of values by providing
a tuple

r"Table %d.*?%s.*?\n.*?\d(.*?)\n.*?" % (j, char)

or a dict

r"Table %(table)d.*?%(char)s.*?\n.*?\d(.*?)\n.*?" % dict(table=j, char=char)

on the right side of the % operator.

http://docs.python.org/lib/typesseq-strings.html

Peter
Feb 16 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

83 posts views Thread by D. Dante Lorenso | last post: by
3 posts views Thread by RiceGuy | last post: by
4 posts views Thread by kreepssss | last post: by
reply views Thread by Chung Leong | last post: by
1 post views Thread by vikjohn | last post: by
1 post views Thread by Korara | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.