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.
- what equivalent way of solving problem in python?
- 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
Post a Comment