title: Why is name Node not defined?
body: <p>I am new to Python and i am getting this error, but am unsure why:</p>
  
  <p><code>NameError: name 'Node' is not defined</code></p>
  
  <pre><code>class Node:
  # initialisation/constructor
      def __init__(self):
          self.parents = []
          self.children = []
          self.parentWeights = []
          self.nodeWeight = 0.0
  
      # add child to node
      def addChild(self, child, weight):
          self.children.append(child)
  
      # add parent with weight to node
      def addParent(self, parent, weight):
          self.parents.append(parent)
          self.parentWeights.append(weight)
  
          if not self in parent.children:
              parent.addChild(self, weight)
  
      def calculateWeight(self):
          weightSum = sum(self.parentWeights)*self.nodeWeight
          self.nodeWeight = weightSum
  
      # run main function if not a library
  
      if __name__ == '__main__':
          i1 = Node()
          i2 = Node()
          h1 = Node()
          h2 = Node()
          o1 = Node()
  
          h1.addParent(i1, 1)
          h1.addParent(i2, 1)
          h2.addParent(i2, 1)
          h2.addParent(i2, 1)
          o1.addParent(h1, -1)
          o1.addParent(h2, 1)
  
          i1.nodeWeight = 3
          i2.nodeWeight = 5
          calculateWeight(h1)
          calculateWeight(h2)
          calculateWeight(o1)
  </code></pre>