You could of course do a lookup for the object in whatever scope it is. If the object is in global scope you find it by using globals()[name]
if it's in a instance or class attribute you'd use getattr(obj_or_class, name)
.
However you could use an object that refers or can create the other object on demand instead of having to do a lookup - this would have the advantage of not needing to know where to lookup the other object. For example:
class FootCreator:
def __init__(*args, **kwds):
self.args = args
self.kwds = kwds
def other(self, other):
self.other = other
def __call__(self):
try:
return self.feets
except:
pass
self.feets = Feets(other=self.other, *self.args, self.**kwds)
return self.feets
class Feets:
def get_other(self):
return self.other()
The solution where you set the reference to the other explicitely after creation might be non-OO since it might break invariance (but on the other hand the objects will not be complete until the other has been created anyways). A similar solution would be to create and initialize the object separately:
lf = Feets.__new__() # lf created, but not initialized yet
rf = Feets.__new__() # rf created, but not initialized yet
lf.__init__(..., other=rf) # initialize (existing) lf
rf.__init__(..., other=lf) # initialize (existing) rf