title: python NameError: name '<anything>' is not defined (but it is!)
body: <p><strong>Note: Solved. It turned out that I was importing a previous version of the same module.</strong></p>
  
  <p>It is easy to find similar topics on StackOverflow, where someone ran into a NameError. But most of the questions deal with specific modules and the solution is often to update the module.</p>
  
  <p>In my case, I am trying to import a function from a module that I wrote myself. The module is named InfraPy, and it is definitely on sys.path. One particular function (called listToText) in InfraPy returns a NameError, but only when I try to import it into another script. Inside InfraPy, under <code>if __name__=='__main__':</code>, the listToText function works just fine. From InfraPy I can import other functions with no problems. Including <code>from InfraPy import *</code> in my script does not return any errors until I try to use the listToText function.</p>
  
  <p>How can this occur?<br>
  How can importing one particular function return a NameError, while importing all the other functions in the same module works fine?</p>
  
  <p>Using python 2.6 on MacOSX 10.6, also encountered the same error running the script on Windows 7, using IronPython 2.6 for .NET 4.0</p>
  
  <p>Thanks.</p>
  
  <p>If there are other details you think would be helpful in solving this, I'd be happy to provide them.</p>
  
  <p>As requested, here is the function definition inside of InfraPy:</p>
  
  <pre><code>def listToText(inputList, folder=None, outputName='list.txt'):
      '''
      Creates a text file from a list (with each list item on a separate line). May be placed in any given folder, but will otherwise be created in the working directory of the python interpreter.
      '''
      fname = outputName
      if folder != None:
          fname = folder+'/'+fname
      f = open(fname, 'w')
      for file in inputList:
          f.write(file+'\n')
      f.close() 
  </code></pre>
  
  <p>This function is defined above and outside of <code>if __name__=='__main__':</code></p>
  
  <p>I've tried moving InfraPy around in relation to the script. The most baffling situation is that when InfraPy is <em>in the same folder</em> as the script, and I import using <code>from InfraPy import listToText</code>, I receive this error: <code>NameError: name listToText is not defined</code>. Again, the other functions import fine, they are all defined outside of <code>if __name__=='__main__':</code> in InfraPy.</p>