title: "NameError: name '<tableName>' is not defined" in SQLAlchemy when Importing Data
body: <p>When trying to import user data from a JSON file into a database using the SQLAlchemy expression language, I get the error:
  <code>NameError: name 'users' is not defined</code></p>
  
  <p>The traceback is as follows:</p>
  
  <pre><code>Traceback (most recent call last):
    File     "C:\Users\lmills\MyProject\Database-Configuration\CreateTable.py", line 43, in &lt;module&gt;
      importData.userDataImport()
    File      "C:\Users\lmills\MyProject\Database-Configuration\importData.py", line 11, in userDataImport
      conn.execute(users.insert(), userid = userData[i]['userid'], altuid = userData[i]['altuid'], lname = userData[i]['lname'], fname = userData[i]['fname'], phoneNum = userData[i]['phoneNum'], emailAddr = userData[i]['emailAddr'])
  NameError: name 'users' is not defined
  </code></pre>
  
  <p>I issue the create table statements in a Python program, CreateTable.py:</p>
  
  <pre><code>from sqlalchemy import create_engine, Table, Column, Integer, String,     
  MetaData, ForeignKey
  import importData
  import json
  
  engine = create_engine('sqlite:///MyProject.db', echo=True)
  metadata = MetaData(engine)
  
  metadata.drop_all(engine)
  
  users = Table('users', metadata,
      Column('userid', Integer, primary_key=True),
      Column('altuid', String(12)),
      Column('lname', String(32)),
      Column('fname', String(32)),
      Column('phone_num', Integer, nullable=False),
      Column('email_addr', String(32), nullable=False),
  )
  
  subscribables = Table('subscribables', metadata,
      Column('subtag', Integer, primary_key=True),
      Column('message_template', String(64)),
      Column('descriptor_string', String(64)),
  )
  
  user_subs = Table('user_subs', metadata,
      Column('userid', Integer, ForeignKey('users.userid')),
      Column('subtag', Integer, ForeignKey('subscribables.subtag')),
  )
  
  user_prefs = Table('user_prefs', metadata,
      Column('userid', Integer, ForeignKey('users.userid')),
      Column('type_id', String(8), ForeignKey('notification_type.type_id')),
  )
  
  notification_type = Table('notification_type', metadata,
      Column('type_id', String(8), primary_key=True),
      Column('typename', String(8), nullable=False),
      Column('Template', String(64)),
  )
  
  metadata.create_all()
  
  importData.userDataImport()
  </code></pre>
  
  <p>Then I attempt to import data using a module, userDataImport, within the importData.py file, which contains the following:</p>
  
  <pre><code>import json
  from sqlalchemy import create_engine
  import sqlalchemy
  
  def userDataImport():
      engine = create_engine('sqlite:///MyProject.db', echo=True)
      conn = engine.connect()
      with open(r'C:\Users\lmills\MyProject\userData.json') as dataFile:
          userData = json.load(dataFile)
              for i in range(len(userData)):
                  conn.execute(users.insert(), userid = userData[i]['userid'], altuid = userData[i]['altuid'], lname = userData[i]['lname'], fname = userData[i]['fname'], phoneNum = userData[i]['phoneNum'], emailAddr = userData[i]['emailAddr'])
  
  if __name__ == "__main__": userDataImport()
  </code></pre>
  
  <p>however SQLAlchemy cannot identify users, which is the table that I had created in CreateTable.py If I move the code from the userDataImport module immediately after  <code>metadata.create_all()</code> in CreateTable.py, everything works fine and dandy; it's in the case where I call this module that I cannot get it to work. 
  I have attempted passing the engine to userDataImport and alternatively passing the connection object to userDataImport, but neither of these attempt proved fruitful (in both cases the engine = ... and conn = ... where removed). Where am I going wrong?</p>