I read that importing a module’s mutable objects and changing them in-place,affects the original imported module’s objects as well.
For instance:
from mymod import x
x[0]=1001
So when I do this:
import mymod
print(mymod.x)
Prints [1001,43,bla].
My question is,does an in-place change this affect a module’s compiled byte code,a module’s source(unlikely isn’t it?) or the namespace that I’ve imported?So if I change something like that,import at a later time the same module somewhere else and try to access the mutable object,what would I get?Cheers.
No, it doesn’t. When you import that module at a later time (or if another script imports the module at the same time your program is still running) you get your own, “clean” copy of that module.
So if the
test.pycontains the single linex = [1,2,3], you get: