Object instantiation in Python -


I have the following Python code for the category PortDataState below.

  class PortDataState (dict): # dict: Port Class - & gt; PortData class # slimed down version does not support Python 2.6 as an ordered date. _PREV = 0 _NEXT = 1 _KEY = 2 def __init __ (self): Super (PortDataState, itself) .__ init __ () self._root = root = [] # Centennial node root [:] = [root, root, any No] # [_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 final = root [self._PREV] last [self._NEXT] = root [self._PREV] = self._map [key] = [last, root , Main] 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 (auto, key): self._remove_key (key) self._prepend_key (key) def add_port (self, port , Lldp_data): If the port is not in itself: self._prepend_key (port) self [port] = PortData (port.is_down (), lldp_data) Other: self [port] .is_down = port.is_down () def lldp_sent (self, Port): P Ort_data = self [port] port_dat a.lldp_sent () self._move_last_key (port) return port_data def lldp_received (self, port): auto [port]. Lldp_received () def move_front (auto, port): port_data = self.get (port, none) if there is no port: 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 i_down: self._move_front_key (port) return_down def get_port (auto, 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 the curr is not root: yield curr [self._KEY] curr = curr [self._NEXT] def explicit (self): for node in self._map.itervalues ​​(): del node [:] root = self._root root [:] = [root, Root, none] self._map.clear () dict.clear (self) def item (self): 'od.items () - & gt; Odi 'return (key, value) list of pairs [key for self in [[key, self [key]) def ITRTimes (self):' od.iteritems - & gt; In the self (k, itself, [k]), in the second category, I get an object of PortDataState immediately below. I am transforming  
  self.ports = PortDataState () # port class - & gt; PortData class   

I am very new to Python. I should know what are ourselves? I really do not find that the __init __ function of PortDatest is doing the above. What specifically happens

  def __init __ (self): super (PortDATESTATE, itself) .__ init__ () Self._root = root = [] # Centennial node root [:] = [Root, root, none] # [_PREV, _NEXT, _KEY] # doubly linked list { p> 

__ init __ function is a functional method in any form, second language. This method initializes the class field (but the __init __ method is not for making the object itself, __init __ is created only after the modified object). The object creative is automatically displayed when your portatastet () is written (i.e. when the object is indenting)

The self.ports for your case object will include all the methods and variables contained in the dict class (because PortDataStates has inherited from dict). In addition to your object:

  1. _PREV , _NEXT , _KEY variable (this will be a fixed variable and portatastet
  2. _root , _map - some types of "protected" subscribers (if you use IDE, , It warns you that if you try to reach out to any of these members then this member is protected). But actually during execution, Python does not stop you from using "_" char from the member (so it is only the conference).
  3. link_prev , first will not be presented in the object because this keyword has not started with . itself is the object itself.

Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -