Consider these three files:
base.py
class Base():
def method(self):
print('Base Class')
object = Base()
main.py
from base import object
def main():
object.method()
if __name__ == '__main__':
main()
test.py
import main
import base
class Derived(base.Base):
def method(self):
print('Derived Class')
base.object = Derived()
main.main()
I would expect that launching test.py will invoke the method() function of derived class but it is not.
$ python3.8 test.py
Base Class
But it works if I change the way I import object in main.py
new main.py
import base
def main():
base.object.method()
if __name__ == '__main__':
main()
new output:
$ python3.8 test.py
Derived Class