469,622 Members | 2,001 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

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

Simulating call-by-value

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

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
Sincerely, | http://bos.hack.org/cv/
Rikard Bosnjakovic | Code chef - will cook for food
Nov 22 '05 #1
0 991

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by jimif_fr | last post: by
12 posts views Thread by cppaddict | last post: by
47 posts views Thread by Lauren Quantrell | last post: by
3 posts views Thread by Doug Eleveld | last post: by
6 posts views Thread by bwahahahaha | last post: by
6 posts views Thread by Timo | last post: by
8 posts views Thread by John Dann | last post: by
reply views Thread by Andrew Teece | last post: by
4 posts views Thread by Bill Pursell | last post: by
2 posts views Thread by Ian Collins | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.