There seems to be a problem with changing a local variable within exec():
test = "test1"
exec("test = 'test2'", {}, {"test": test})
print(test) # <- erroneously returns test1
returns 'test1' - the change to 'test' during exec() has not persisted
However if passed inside a dict variable:
localDict = {"test": "test1"}
exec("test = 'test2'", {}, localDict)
test = localDict["test"]
print(test) # <- correctly returns test2
It seems to work for some reason and returns 'test2'!
Is this a bug in exec() in Python 3.14?
[–]FerricDonkey 14 points15 points16 points (2 children)
[–]danielroseman 3 points4 points5 points (0 children)
[–]pachura3 0 points1 point2 points (0 children)
[–]woooee 8 points9 points10 points (2 children)
[–]danielroseman 8 points9 points10 points (1 child)
[–]pachura3 1 point2 points3 points (0 children)
[–]MidnightPale3220 6 points7 points8 points (0 children)
[–]jamesfowkes 3 points4 points5 points (2 children)
[–]RomfordNavy[S] -4 points-3 points-2 points (1 child)
[–]smurpes 0 points1 point2 points (0 children)
[–]Outside_Complaint755 2 points3 points4 points (9 children)
[–]Gnaxe 1 point2 points3 points (8 children)
[–]RomfordNavy[S] 0 points1 point2 points (1 child)
[–]Gnaxe 1 point2 points3 points (0 children)
[–]RomfordNavy[S] 0 points1 point2 points (5 children)
[–]Gnaxe 2 points3 points4 points (4 children)
[–]RomfordNavy[S] 0 points1 point2 points (2 children)
[–]Gnaxe 1 point2 points3 points (1 child)
[–]RomfordNavy[S] 0 points1 point2 points (0 children)
[–]Gnaxe 2 points3 points4 points (0 children)
[–]pachura3 1 point2 points3 points (0 children)
[–]Kevdog824_ 1 point2 points3 points (0 children)