python StringBuilder for MySQL query execution -


i trying query database 1 of columns python variable:

weeknum = "week" + str(i)               #i either 2, 3, 4, 5 cur.execute("select %s golden_table ngram = %s , hash_tag = %s", (weeknum, tup[0], tup[1])) 

note sql table: golden_table includes 4 columns: week2 week3 week4 week5. however, python or mysql not treating value of weeknum column. instead returned query value "weeki." above. in java, know way around stringbuilder class.

  1. what equivalent way of solving problem in python?
  2. what better way solve in python?

all appreciated, , let me know if need more information.

if python version recent (2.6+). use format.

weeknum = "week" + str(i)               #i either 2, 3, 4, 5 query = "select {0} golden_table ngram = %s , hash_tag = %s".format(weeknum) cur.execute(query, (tup[0], tup[1])) 

Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

c# - must be a non-abstract type with a public parameterless constructor in redis -

ajax - PHP/JSON Login script (Twitter style) not setting sessions -