Take the 2-minute tour ×

I want to replace v__a with z3Sigs but the following code doesn't do that.

import re
SigOnDecision = ['v__a', '__Vdly__v__a']
x = "(1 & v__a) == 0"
for signs in SigOnDecision:
    p = "{}".format(signs)
    y = re.sub(p, "z3Sigs", x)
print y

This code prints the original value of x only i.e. (1 & v__a) == 0 Can anyone point out the error

share|improve this question

1 Answer 1

up vote 2 down vote accepted

It's because you don't modify y. You only replace the value of x:

y = re.sub(p, "z3Sigs", x)

Modify x instead:

x = re.sub(p, "z3Sigs", x)

Or set y to x and modify y:

y = x

for signs in SigOnDecision:
    y = re.sub(p, "z3Sigs", y)
share|improve this answer

Your Answer


