當前位置: 首頁>>代碼示例>>Python>>正文


Python Node.Node方法代碼示例

本文整理匯總了Python中Node.Node方法的典型用法代碼示例。如果您正苦於以下問題:Python Node.Node方法的具體用法?Python Node.Node怎麽用?Python Node.Node使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Node的用法示例。


在下文中一共展示了Node.Node方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: initialize

# 需要導入模塊: import Node [as 別名]
# 或者: from Node import Node [as 別名]
def initialize():
    """This function initializes the application"""

    #Gather information about the current device and display it
    thisNode = Node(fetch_IP_address(), fetch_MAC_address(), fetch_broadcast_address(), scanHosts())
    print("My IP is {} and MAC is {}\n".format(thisNode.getIPAddress, thisNode.getMACAddress))

    #Register this device as a listener for incoming messages
    listener = Listener(thisNode)

    #Election of a master node
    begin_election_process(thisNode, listener)

    #Initialises threads for scanning devices and messaging
    scanner_thread = threading.Thread(target=network_scanner, args=(thisNode,listener))
    listener_thread = threading.Thread(target=network_listener, args=(listener,))

    #start scanning and listener threads
    scanner_thread.start()
    listener_thread.start() 
開發者ID:mcvavy,項目名稱:pyNet,代碼行數:22,代碼來源:start.py

示例2: SelectNodeColor

# 需要導入模塊: import Node [as 別名]
# 或者: from Node import Node [as 別名]
def SelectNodeColor(self,state):
        nodes1 = [item for item in self.scene().items() if isinstance(item, Node)]
        if state == "Correlation Strength": 
            self.ColorNodesBasedOnCorrelation = True 
            for node in nodes1:
                node.NodeColor()
            self.Tab_2_CorrelationTable().hide()
            self.CommunityMode.emit(False)
        else: 
            self.ColorNodesBasedOnCorrelation = False 
            if not(self.level == -1):
                self.communityDetectionEngine.ChangeCommunityColor(self.level)
            else: 
                self.communityDetectionEngine.ChangeCommunityColor()
            self.CommunityMode.emit(True)
            self.CommunityColor.emit(self.ColorToBeSentToVisit)
        self.Scene_to_be_updated.update()
        del nodes1 
開發者ID:sugeerth,項目名稱:ECoG-ClusterFlow,代碼行數:20,代碼來源:Graph_interface.py

示例3: insert

# 需要導入模塊: import Node [as 別名]
# 或者: from Node import Node [as 別名]
def insert(self, key, data):
        """
        Insert new key into node
        """
        # Create new node
        n = Node(key, data)

        # Initial tree
        if not self.node:
            self.node = n
            self.node.left = AVLTree()
            self.node.right = AVLTree()
        # Insert key to the left subtree
        elif key < self.node.key:
            self.node.left.insert(key, data)
        # Insert key to the right subtree
        elif key > self.node.key:
            self.node.right.insert(key, data)

        # Rebalance tree if needed
        self.rebalance() 
開發者ID:amrelarabi,項目名稱:spell-checker-with-python-3,代碼行數:23,代碼來源:AVLTree.py

示例4: insertAtFront

# 需要導入模塊: import Node [as 別名]
# 或者: from Node import Node [as 別名]
def insertAtFront(self,data):
        newNode = Node()
        newNode.setData(data)
        newNode.setNext(newNode)
        if self.length==0:
            self.head = newNode
            newNode.setNext(self.head)
            self.length += 1
        else:
            tempNode = self.head
            while tempNode.getNext() != self.head:
                tempNode = tempNode.getNext()
            tempNode.setNext(newNode)
            newNode.setNext(self.head)
            self.head = newNode
            self.length+=1 
開發者ID:ridwanrahman,項目名稱:datastructures,代碼行數:18,代碼來源:circularLinkedList.py

示例5: network_scanner

# 需要導入模塊: import Node [as 別名]
# 或者: from Node import Node [as 別名]
def network_scanner(thisNode, listener):
    '''Thread to forever loop scanning the network'''
    while True:
        try:
            print("Scanning for new hosts............\n")
            newHostScans = scanHosts()
        except subprocess.CalledProcessError as e:
            print('nmam error')
            time.sleep(60*5)
            continue



        """ Looping through the newly scanned hosts"""
        #Check if each host in the new list is in our current list
        for host in newHostScans:
            if host not in thisNode.getCurrentHosts:
                thisNode.add_node(host)

        """Ping all addresses on our list to check if they are alive or dead"""
        for host in thisNode.getCurrentHosts:
            if command_executor(host[0]) == '':
                thisNode.remove_node(host)

        '''Check if master is alive/dead then raise election requests'''
        if not thisNode.getMasterNode:
            begin_election_process(thisNode, listener)
        else:
            if command_executor(thisNode.getMasterNode[0]) == '':
            #We kickoff election contest
                begin_election_process(thisNode, listener)

        if command_executor(thisNode.getIPAddress) == '':
            thisNode.update_ip_address(fetch_IP_address())
            begin_election_process(thisNode, listener)

        time.sleep(5)

        if thisNode.getMasterNode:
            print("Current Master is Node with IP: {} ,  MAC: {}, Vendor: {}\n\n".format(thisNode.getMasterNode[0],thisNode.getMasterNode[1],thisNode.getMasterNode[2]))
        print("Current live hosts are {}\n\n".format(thisNode.getCurrentHosts)) 
開發者ID:mcvavy,項目名稱:pyNet,代碼行數:43,代碼來源:start.py

示例6: create_mynode

# 需要導入模塊: import Node [as 別名]
# 或者: from Node import Node [as 別名]
def create_mynode():
    import Node

    my_ip = get_node_ip()

    new_node = Node.Node(my_ip)

    mynode_jobj = {
        'type': new_node.type,
        'ip_address': new_node.ip_address
    }

    j_str = json.dumps(mynode_jobj)

    return mynode_jobj, j_str 
開發者ID:JoohyeongSong,項目名稱:EV3-Project,代碼行數:17,代碼來源:NodeController.py

示例7: bstInsert

# 需要導入模塊: import Node [as 別名]
# 或者: from Node import Node [as 別名]
def bstInsert(self, subtree, key, value):
        if subtree is None:
            subtree = Node(key, value)
        elif key < subtree.key:
            subtree.left = self.bstInsert(subtree.left, key, value)
        elif key > subtree.key :
            subtree.right = self.bstInsert(subtree.right, key, value)
        return subtree

    # Removes the node associated with the given key. 
開發者ID:amrelarabi,項目名稱:spell-checker-with-python-3,代碼行數:12,代碼來源:BinarySearchTree.py

示例8: insertAtBeginning

# 需要導入模塊: import Node [as 別名]
# 或者: from Node import Node [as 別名]
def insertAtBeginning(self, data):
        newNode = Node(data)
        if (self.head == None):
            self.head = self.tail = newNode
            self.length += 1
        else:
            newNode.setPrev(None)
            newNode.setNext(self.head)
            self.head.setPrev(newNode)
            self.head = newNode
            self.length += 1 
開發者ID:ridwanrahman,項目名稱:datastructures,代碼行數:13,代碼來源:doublyLinkedList.py

示例9: insertAtEnd

# 需要導入模塊: import Node [as 別名]
# 或者: from Node import Node [as 別名]
def insertAtEnd(self, data):
        currentNode = self.head
        newNode = Node(data)
        if (self.head == None):
            self.head = newNode
            self.tail = self.head
        else:
            while currentNode.getNext()!=None:
                currentNode = currentNode.getNext()
            currentNode.setNext(newNode)
            newNode.setPrev(currentNode)
            newNode.setNext(None) 
開發者ID:ridwanrahman,項目名稱:datastructures,代碼行數:14,代碼來源:doublyLinkedList.py

示例10: insertAtPos

# 需要導入模塊: import Node [as 別名]
# 或者: from Node import Node [as 別名]
def insertAtPos(self, data, pos):
        newNode = Node(data)
        if self.head == None or pos == 0:
            self.insertAtBeginning(data)
        else:
            tempNode = self.getNode(pos)
            newNode.setPrev(tempNode.getPrev())
            tempNode.getPrev().setNext(newNode)
            newNode.setNext(tempNode)
            tempNode.setPrev(newNode)
            self.length += 1 
開發者ID:ridwanrahman,項目名稱:datastructures,代碼行數:13,代碼來源:doublyLinkedList.py

示例11: insertAtEnd

# 需要導入模塊: import Node [as 別名]
# 或者: from Node import Node [as 別名]
def insertAtEnd(self, data):
        newNode = Node()
        newNode.setData(data)
        newNode.setNext(newNode)
        if self.length==0:
            self.head = newNode
            newNode.setNext(self.head)
            self.length += 1
        else:
            currentNode = self.head
            newNode.setNext(self.head)
            while currentNode.getNext()!=self.head:
                currentNode = currentNode.getNext()
            currentNode.setNext(newNode)
            self.length+=1 
開發者ID:ridwanrahman,項目名稱:datastructures,代碼行數:17,代碼來源:circularLinkedList.py

示例12: push

# 需要導入模塊: import Node [as 別名]
# 或者: from Node import Node [as 別名]
def push(self,data):
        newNode = Node()
        newNode.setData(data)
        if self.length == 0:
            newNode.setNext(self.head)
            self.head = newNode
            self.temp_first_node = newNode
            self.length += 1
        else:
            newNode.setNext(self.head)
            self.head = newNode
            self.length +=1 
開發者ID:ridwanrahman,項目名稱:datastructures,代碼行數:14,代碼來源:Stack.py

示例13: insert

# 需要導入模塊: import Node [as 別名]
# 或者: from Node import Node [as 別名]
def insert(self, data):
        # if we are inserting a node for the first time
        if not self.rootNode:
            self.rootNode = Node(data)
        else:
            self.rootNode.insertRecursive(data)

    # method to remove a node 
開發者ID:pranavj1001,項目名稱:LearnLanguages,代碼行數:10,代碼來源:BinarySearchTree.py

示例14: remove

# 需要導入模塊: import Node [as 別名]
# 或者: from Node import Node [as 別名]
def remove(self, dataToRemove):
        # check if the tree is empty or not
        if self.rootNode:
            # if we have to remove the root node
            if self.rootNode.data == dataToRemove:
                # create a new node
                tempNode = Node(None)
                # make its leftChild the rootNode
                tempNode.leftChild = self.rootNode
                # then continue with the remove process
                self.rootNode.removeRecursive(dataToRemove, tempNode)
            else:
                self.rootNode.removeRecursive(dataToRemove, None)

    # method to display the max node of the tree 
開發者ID:pranavj1001,項目名稱:LearnLanguages,代碼行數:17,代碼來源:BinarySearchTree.py

示例15: putItem

# 需要導入模塊: import Node [as 別名]
# 或者: from Node import Node [as 別名]
def putItem(self, node, key, value, index):

        # get the character from the key
        # initially index is zero i.e. get the first char initially
        character = key[index]

        # if there's no node for the current character then create a new node
        if node is None:
            node = Node(character)

        # if the character has a lesser value than the current node then go left
        if character < node.char:
            node.leftNode = self.putItem(node.leftNode, key, value, index)

        # if the character has a greater value than the current node then go right
        elif character > node.char:
            node.rightNode = self.putItem(node.rightNode, key, value, index)

        # when the above two conditions are false
        # and we have not traversed through the entire characters of the key
        # then go middle
        elif index < len(key) - 1:
            node.middleNode = self.putItem(node.middleNode, key, value, index + 1)

        # insert the value here as we have traversed through the characters of the key
        else:
            node.value = value

        return node

    # function to get the value from the key 
開發者ID:pranavj1001,項目名稱:LearnLanguages,代碼行數:33,代碼來源:TST.py


注:本文中的Node.Node方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。