开始吧:
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()
太酷了-它给了Burek
但将这些类传播到不同的文件中,即:
^{pr2}$其他文件:
from calls_inh.parent_page import Parent
class Child(Parent):
def __init__(self):
super(Child, self).__init__()
self.doge_name = 'Burek'
退货:
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
回答发生了什么Circular dependency in Python
溶液How to avoid circular imports in Python? 更改父类中的导入和调用使其在单独的文件中工作
相关问题 更多 >
编程相关推荐