【发布时间】:2011-06-22 10:01:46
【问题描述】:
我已经问过这个问题,但它的表述不是很好。
persistence of objects in python
作为python和GUI编程的新手
我有一个包含许多 python 文件的大型项目。文件 a.py 定义了一个名为 fobject 的类我使用的是 python 2.5
文件 b.py 和 c.py 有名为 BProject 和 CProject 的类,它们有一个 fobject 对象作为参数。这些是基于 wx python 的程序中的页面。
我在 b.py 中包含了使用 import CProject(在 c.py 中定义)。我在 CProject 中有一个使用 wx python GUI 填充的列表。接下来我调用在 BProject 中定义的函数 BRun,它在内部调用 CProject 中的 CRun 函数,即。在 c.py.
在这个 CRun 中,我想操作列表,但此时列表始终为空。为什么会这样?
鉴于约束条件是我无法更改定义 fobject 的任何 a.py 内容,我应该怎么做?
文件: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()
当调用 CPython.OnIntRun 时 self.IntList 不应该为空
【问题讨论】: