The problem is that in Manager.__init__
, you call __setattr__
to set the attribute person
. But in __setattr__
, you assume that self.person
has already been set and has a well defined __dict__
. In reality, it hasn't been set yet, so you end up calling __getattr__
which calls itself forever trying to get self.person
.
One possible fix here is to bypass the initial call to __setattr__
in Manager.__init__
:
class Manager(object):
def __init__(self,name,pay):
self.__dict__['person']=Person(name,'mgr',pay)
This should avoid the call to "__getattr__('person')
" since self.person
will already be set and normal attribute lookup will work1.
1__getattr__
is only called if normal attribute lookup fails