python实现类之间的方法互相调用
时间:2021-01-11 11:02:37|栏目:Python代码|点击: 次
all.py
from son import * class ALL(): def __init__(self): self.mSon = SON(self) def getAll(self): print "=================getall---------------" return self.mSon.getSon() def getAlltest(self): print "=================getAlltest---------------" Instance = ALL() Instance.getAll()
son.py
class SON(): def __init__(self, instance): self.mBattle = instance def getSon(self): return self.mBattle.getAlltest()
son.py和all.py在同一个文件夹下面,可以通过from son import *或者 import son 来互相调用。
可以动态实例化son.py里面的SON类,而且也可以把ALL的实例通过参数传递给SON,从而调用ALL类的方法。
上一篇:Python单链表的简单实现方法
栏 目:Python代码
下一篇:PyQt5实现简易计算器
本文标题:python实现类之间的方法互相调用
本文地址:http://www.codeinn.net/misctech/43790.html






