Here we go:
class Parent(object):
def doge(self):
print Child().doge_name
class Child(Parent):
def __init__(self):
super(Child, self).__init__()
self.doge_name = 'Burek'
if __name__ == '__main__':
Parent().doge()
So cool - its gives Burek
But spreading this classes to different files i.e.:
from calls_inh.child_ppage import Child
class Parent(object):
def doge(self):
print Child().doge_name
if __name__ == '__main__':
Parent().doge()
other file:
from calls_inh.parent_page import Parent
class Child(Parent):
def __init__(self):
super(Child, self).__init__()
self.doge_name = 'Burek'
returns:
Traceback (most recent call last): File
"D:/check/calls_inh/parent_page.py", line 1, in <module>
from calls_inh.child_ppage import Child File "D:\check\calls_inh\child_ppage.py", line 1, in <module>
from calls_inh.parent_page import Parent File "D:\check\calls_inh\parent_page.py", line 1, in <module>
from calls_inh.child_ppage import Child ImportError: cannot import name Child
Process finished with exit code 1
- Why it pass in one case and fails in other?
- Is there any way to make it works like in one file?