到目前爲止,我只用C語言完成了過程編程,所以我對OOP和Python都不太清楚。python中對象的持久性
我有一個大項目,其中包含一些python文件。 文件a.py定義名爲fobject 我使用蟒2.5
文件b.py類和c.py具有類稱爲BProject和的CProject具有fobject作爲參數的對象。 我已經包含在b.py中使用導入CProject(在c.py中定義)。 我在CProject中使用wx python GUI填充了一個列表。 接下來我調用一個在BProject中定義的函數BRun,它在內部調用CProject中的CRun函數即。在c.py中。
在這個CRun中,我想操作列表,但列表總是空的。這是爲什麼?
我應該怎麼做給定的約束是我不能改變任何a.py中定義的fobject?
文件:c.py
def Instance(fObject):
return test_page_CProject(fObject)
class CProject(object):
def __init__(self, fObject):
self.fObj = fObject
self.IntList = []
##snip
def OnIntSelectBtnPress(self,parent):
print ":self.IntList"
print self.IntList
self.listBoxIntSelect.InsertItems(self.IntList,0)
print self.IntList
def OnIntRun(self):
IntLModeList = self.IntListIntMode
#snip
文件b.py
def Instance(fObject):
return BProject(fObject)
class BProject(object):
def __init__(self, fObject):
self.FObj = fObject
#snip
Object = __import__('CProject')
#snip
self.intObject = Object.Instance(self.FObj)
self.intObject.OnIntRun()
你能發表相關的代碼嗎? – user122211
這個問題很混亂,目前基本上不可能回答。顯示代碼將有所幫助。 – Omnifarious
請好好發佈相關代碼以瞭解問題。 – sam