Reputation:
I have file abcd.py
a=9
def funn():
print("A")
I import it two times
>>> import abcd as ss
>>> ss.a
9
>>> import abcd as qq
>>> qq.a
9
But When I change value of a
from ss
imported file, qq
import file value of a
is automatically change.
>>> ss.a=4
>>> ss.a
4
>>> qq.a
4
Upvotes: 0
Views: 53
Reputation: 55499
Python doesn't actually re-import a module that it's already imported. So when you do
import abcd as qq
you're simply creating another name for the abcd
module, which you've already imported as ss
. So ss.a
and qq.a
are just synonyms for the same integer object.
You may find this article helpful: Facts and myths about Python names and values, which was written by SO veteran Ned Batchelder.
Upvotes: 3