擅长:python、mysql、java
<p>我仍然不知道你想要什么,这里有一个方法来读取一个文件,并在文本中添加一个变量名</p>
<pre><code>query = ""
f = open("query_file",'r')
query = f.read() # read the query file into a string
f.close()
for x in reviewers:
query = query+reviewers[count] # add variable name in the string assuming reviewers[count] gives a string
cur.execute(query)
count = count + 1
#do more stuff
</code></pre>
<p><strong>编辑</p>
<p>Python中的一个重要点是字符串是不可变的</p>
<p>如果要修改字符串,则必须创建一个新字符串</p>
<p>例如</p>
<pre><code>query = "Select from Table"
</code></pre>
<p>你想让它<code>Select Col from Table</code></p>
<p>以下是您的工作:</p>
<pre><code>add_me = "Col"
new_string = query[:-10] + add_me + query[6:]
</code></pre>
<p>现在<code>new_string</code>字符串将有<code>Select Col from Table</code></p>