擅长:python、mysql、java
<p>我认为您需要使用参数替换功能:</p>
<pre><code>cur.execute("SELECT * FROM list WHERE InstitutionName=?", (Variable,))
</code></pre>
<p>在<a href="http://docs.python.org/2/library/sqlite3.html#sqlite3.Cursor.execute">actual execute command</a>和<a href="http://docs.python.org/2/library/sqlite3.html">sqlite3 docs page</a>上的第4个示例代码框中有更多文档。</p>
<p>请注意,您应该显式不要使用<code>%</code>或<code>format</code>函数</em>,因为这容易受到注入攻击:</p>
<pre><code># NEVER DO THIS
cur.execute("SELECT * FROM list WHERE InstitutionName='%s'" % (Variable,))
</code></pre>