title: Access attribute of container from member Python
body: <p>I have a class (<code>PlayerList</code>) that contains <code>Player</code> objects (or subclasses) by inheriting from <code>list</code> builtin. I want each of the <code>Player</code> objects to use the container's attribute <code>true_dice.</code> The problem is that for testing purposes I need each of the players to have the ability to use their own as well, if they are not part of a <code>PlayerList</code></p>
  <pre><code>class PlayerList(list):
      def __init__(plist):
          # plist is a list of Player objects
          self.true_dice = [0,0,0,0]
          super().__init__(plist)
  
  class Player:
      def __init__():
          self.true_dice = &quot;&lt;Magical code that gets containers true_dice&gt;&quot;
      
      def turn(self):
          &quot;...&quot;
          self.true_dice[2] = 1 # Modify true_dice should modify PlayerList's aswell
  </code></pre>
  <p>What is the pythonic way to achieve this? A google search turns up no results.</p>
  <p>I was thinking perhaps overriding <code>__getattribute__</code> would work, but then I would have to store a reference to the <code>PlayerList</code> in the class, and that is a very tightly coupled solution:</p>
  <pre><code>class Player:
  ...
      def __getattribute__(self, attrname):
              if attrname==&quot;true_dice&quot;:
                  return player_list_reference.true_dice # Defined in __init__
              else:
                  return self.__dict__[attrname]
  </code></pre>
  <p>Or perhaps I could run an update function every time a member of the 'PlayerList' changes its <code>true_dice</code> attribute. This would separate concerns rather well...</p>
  <p>Please comment any and all requests for edits.</p>