Simulating call-by-value

R

Rikard Bosnjakovic

I'm tidying up some code. Basically, the code runs a bunch of
regexp-searches (> 10) on a text and stores the match in a different
variable.

Like this:

re1 = r' ..(.*).. '
re2 = r' .... '
re3 = r' .(.*).. '
...
m = re.search(re1, data)
if m:
myclass.bar = m.group(1)

m = re.search(re2, data)
if m:
myclass.foo = m.group(1)

m = re.search(re3, data)
if m:
myclass.baz = m.group(1)


While this code works, it's not very good looking.

What I want is to rewrite it to something like this:

l = [ (re1, myclass.bar),
(re2, myclass.foo),
(re3, myclass.baz),
]

for (x,y) in l:
m = re.search(x, y)
if m: y = m.group(1)
re1 = r' ..(.*).. '

But since Python doesn't work that way, that idea is doomed. What I'm
looking for are other (better) ways or pointers to accomplish this task of
cleanup.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,144
Latest member
KetoBaseReviews
Top