title: Object instantiation in Python
body: <p>I have the following python code for the class PortDataState given below.</p>
  
  <pre><code>class PortDataState(dict):
      # dict: Port class -&gt; PortData class
      # slimed down version of OrderedDict as python 2.6 doesn't support it.
      _PREV = 0
      _NEXT = 1
      _KEY = 2
  
      def __init__(self):
          super(PortDataState, self).__init__()
          self._root = root = []          # sentinel node
          root[:] = [root, root, None]    # [_PREV, _NEXT, _KEY]
                                          # doubly linked list
          self._map = {}
  
      def _remove_key(self, key):
          link_prev, link_next, key = self._map.pop(key)
          link_prev[self._NEXT] = link_next
          link_next[self._PREV] = link_prev
  
      def _append_key(self, key):
          root = self._root
          last = root[self._PREV]
          last[self._NEXT] = root[self._PREV] = self._map[key] = [last, root,
                                                                  key]
  
      def _prepend_key(self, key):
          root = self._root
          first = root[self._NEXT]
          first[self._PREV] = root[self._NEXT] = self._map[key] = [root, first,
                                                                   key]
  
      def _move_last_key(self, key):
          self._remove_key(key)
          self._append_key(key)
  
      def _move_front_key(self, key):
          self._remove_key(key)
          self._prepend_key(key)
  
      def add_port(self, port, lldp_data):
          if port not in self:
              self._prepend_key(port)
              self[port] = PortData(port.is_down(), lldp_data)
          else:
              self[port].is_down = port.is_down()
  
      def lldp_sent(self, port):
          port_data = self[port]
          port_data.lldp_sent()
          self._move_last_key(port)
          return port_data
  
      def lldp_received(self, port):
          self[port].lldp_received()
  
      def move_front(self, port):
          port_data = self.get(port, None)
          if port_data is not None:
              port_data.clear_timestamp()
              self._move_front_key(port)
  
      def set_down(self, port):
          is_down = port.is_down()
          port_data = self[port]
          port_data.set_down(is_down)
          port_data.clear_timestamp()
          if not is_down:
              self._move_front_key(port)
          return is_down
  
      def get_port(self, port):
          return self[port]
  
      def del_port(self, port):
          del self[port]
          self._remove_key(port)
  
      def __iter__(self):
          root = self._root
          curr = root[self._NEXT]
          while curr is not root:
              yield curr[self._KEY]
              curr = curr[self._NEXT]
  
      def clear(self):
          for node in self._map.itervalues():
              del node[:]
          root = self._root
          root[:] = [root, root, None]
          self._map.clear()
          dict.clear(self)
  
      def items(self):
          'od.items() -&gt; list of (key, value) pairs in od'
          return [(key, self[key]) for key in self]
  
      def iteritems(self):
          'od.iteritems -&gt; an iterator over the (key, value) pairs in od'
          for k in self:
              yield (k, self[k])
  </code></pre>
  
  <p>In another class I am instantiating an object of PortDataState as below</p>
  
  <pre><code>self.ports = PortDataState()  # Port class -&gt; PortData class
  </code></pre>
  
  <p>I am very new to Python.I want to know what does self.ports contain? I don't really get what <code>__init__</code> function of PortDataState is doing above.Specifically what does </p>
  
  <pre><code>def __init__(self):
      super(PortDataState, self).__init__()
      self._root = root = []          # sentinel node
      root[:] = [root, root, None]    # [_PREV, _NEXT, _KEY]
                                      # doubly linked list
      self._map = {}
  </code></pre>
  
  <p>mean?</p>