import parent
Larry Bates
lbates at websafe.com
Tue Feb 27 18:30:34 EST 2007
Greg Hoover wrote:
> How does one get access to the class that imported a module. For example:
> foo imports bar -- how does bar access foo?
>
> Thanks.
>
I think we are having a problem understanding what you are asking.
If you mean an instance of class foo contains an instance of
class bar how would bar reference attributes or other data in
foo then I think I'll tackle that one. The best way I've seen
is the way that wxWindows does it.
class bar:
def __init__(self, parent)
self.parent=parent
def somemethod(self):
print self.parent.somelist
class foo:
def __init__(self):
self.somelist=['a','b','c']
self.bars=[]
self.bars.append(bar(self))
At least that's the way I understand it and it seems to work. If
this isn't what you are asking just disregard.
-Larry
More information about the Python-list
mailing list