title: How do you pass through a python variable into sqlite3 query?
body: <p>The code is supposed to execute the query base on the input from the user in the python environment (not within the sql query). For example, the variable is defined in the Python environment, and in raw input for <code>table name = customers</code>, I would expect the query to print the column names of the table customers. </p>
  
  <p>However, the below code report syntax error. If I remove the backward slash and the inner quotation mark, it will report <code>no such column: table_name</code>. It appears that the value <code>customers</code> is not being pass through into the query, and the query is reading <code>table_name</code> as a string. </p>
  
  <p>Please help. Thanks</p>
  
  <pre><code>import sqlite3
  
      def ask_column(db_name, table_name):
          conn = sqlite3.connect(db_name)
          c = conn.cursor()
          c.execute('SELECT sql FROM sqlite_master WHERE type = \'table\' And name = \'table_name\'') 
          print c.fetchall()
          conn.close()
  
  db_name = raw_input("Please type the database name : ")
  table_name = raw_input("Please type the table name: ")
  ask_column(db_name, table_name)
  </code></pre>