title: Python: NameError: global name 'foobar' is not defined
body: <p>I have written the following class:</p>
  
  <pre><code>class myClass(object):
      def __init__(self):
          pass
  
      def foo(self, arg1, arg2):
          pp = foobar(self, arg1, arg2)
          if pp:
              return 42
          else
              return -666
  
  
      def foobar(self, arg1, arg2):
          if arg1 == arg2:
              return 42
          else:
              return None
  </code></pre>
  
  <p>The logic is nonsensical - ignore it. What I am trying to so is to call an instance method from another instance method - and I am getting a <code>NameError</code>. I originally thought that this was due to <code>foo()</code> calling <code>foobar()</code> before it had been defined - but switching the order of the function definitions in the script made no difference.</p>
  
  <p>Does anyone what's causing this error, and how to fix it?</p>