title: "NameError: name [module] is not defined" when importing module in class
body: <p>I have the following test code:</p>
  
  <pre><code>import sqlite3
  
  class database:
      def __init__(self, name):
          self.name = name
  
      def connect(name):
          db = sqlite3.connect("%s.db" % self.name)
          c = db.cursor()
  
      def test(self):
          print (3)
  </code></pre>
  
  <p>If I run <code>database('name').test()</code>, I get <code>3</code>, so that works. But if I try <code>database('name').connect()</code>, I get, "NameError: name 'sqlite3' is not defined"</p>
  
  <p>Classes are relatively new to me and I'm still trying to figure out how they work. Thanks much for any help.</p>
  
  <p>EDIT: See the comments in the answer the the solution. The problem seems to be that I was importing sqlite3 in both the file and the notebook. The solution was to import the module only in the file.</p>