title: Python NameError: name is not defined (related to having default input argument types)
body: <p>I have a problem with the fact that I am calling <code>len(myByteArray)</code> in the input arguments to a function I am declaring. I'd like that to be a default argument, but Python doesn't seem to like it. <code>myByteArray</code> is of type <code>bytearray</code>. See <a href="https://docs.python.org/3.1/library/functions.html#bytearray" rel="nofollow">documentation on bytearray here</a>. I am accessing its built-in <code>find</code> function, <a href="https://docs.python.org/3.5/library/stdtypes.html#sequence-types-list-tuple-range" rel="nofollow">documented here</a> (see "bytes.find").</p>
  
  <p>My function:</p>
  
  <pre><code>def circularFind(myByteArray, searchVal, start=0, end=len(myByteArray)):
      """
      Return the first-encountered index in bytearray where searchVal 
      is found, searching to the right, in incrementing-index order, and
      wrapping over the top and back to the beginning if index end &lt; 
      index start
      """
      if (end &gt;= start):
          return myByteArray.find(searchVal, start, end)
      else: #end &lt; start, so search to highest index in bytearray, and then wrap around and search to "end" if nothing was found 
          index = myByteArray.find(searchVal, start, len(myByteArray))
          if (index == -1):
              #if searchVal not found yet, wrap around and keep searching 
              index = myByteArray.find(searchVal, 0, end)
          return index 
  </code></pre>
  
  <p>Examples to attempt to use the function above:</p>
  
  <pre><code>#-------------------------------------------------------------------
  #EXAMPLES:
  #-------------------------------------------------------------------
  #Only executute this block of code if running this module directly,
  #*not* if importing it
  #-see here: http://effbot.org/pyfaq/tutor-what-is-if-name-main-for.htm
  if __name__ == "__main__": #if running this module as a stand-alone program
      import random
      random.seed(0)
  
      bytes = bytearray(100)
      for i in range(len(bytes)):
          bytes[i] = int(random.random()*256)
  
      print(list(bytes)); print();
  
      print('built-in method:')
      print(bytes.find(255))
      print(bytes.find(2,10,97))
      print(bytes.find(5,97,4))
  
      print('\ncircularFind:')
      print(circularFind(bytes,255))
      print(circularFind(bytes,2,10,97))
      print(circularFind(bytes,5,97,4))
  </code></pre>
  
  <p>Error: </p>
  
  <blockquote>
    <p>NameError: name 'myByteArray' is not defined</p>
  </blockquote>
  
  <p>If I just remove my default arguments (<code>=0</code> and <code>=len(myByteArray)</code>), however, it works fine. But...I really want those default arguments there so that the <code>start</code> and <code>end</code> arguments are optional. What do I do? </p>
  
  <p>In C++ this would be easy, as argument types are specified when you write functions.</p>