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實現類之間的方法互相調用就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持武林站長站。
新聞熱點
疑難解答