I have the following modules:
File a.py
class Foo(object):
x = 5
if __name__ == '__main__':
print Foo.x
Foo.x = 7
print Foo.x
b = __import__('b')
print b.Bar.x
File b.py
from a import Foo
class Bar(Foo):
pass
File c.py
if __name__ == '__main__':
import a
print a.Foo.x
a.Foo.x = 7
print a.Foo.x
b = __import__('b')
print b.Bar.x
If I run a.py, I get 5,7,5, and if I run b.py, I get 5,7,7. I am not sure what the correct answer should be, but I would expect that they would be agreed.
source
share