Sharad
Sharad

Reputation: 553

re.sub() not replacing value in an expression

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

Upvotes: 2

Views: 176

Answers (1)

Blender
Blender

Reputation: 298136

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)

Upvotes: 2

Related Questions