In Python, is it possible to get the object, say Foo, that contains another object, Bar, from within Bar itself? Here is an example of what I mean
class Foo(object):
def __init__(self):
self.bar = Bar()
self.text = "Hello World"
class Bar(object):
def __init__(self):
self.newText = foo.text #This is what I want to do,
#access the properties of the container object
foo = Foo()
Is this possible? Thanks!
Foo.__init__,self.bar = Foo()should beself.bar = Bar(). Otherwise you've got an infinite loop (in order to create a Foo, you first have to create a Foo). - Hugh Bothwell