我正在尝试用常量字符串创建id号。但当我执行这个程序时,它是把输入数乘以我的输入值。我只想加上:
dgNotListesi\ U txtGelisimDurumu\ U 0公司 第1页 第二阶段 dgNotListesi\ U txtGelisimDurumu\ 3号 ... (输入值。)
以下是m代码:
import pymysql.cursors
conn = pymysql.connect(host='localhost', port=3306, user='root', passwd='sanane13', db='python')
with conn.cursor() as cursor:
# Create a new record
sql = "INSERT INTO `deneme` (`id_1`) VALUES (%s)"
x=0
y = eval(input("please insert number of students: "))
while x<y:
value = "dgNotListesi_txtGelisimDurumu_%s" %y
x = x+1
cursor.execute(sql, (value, ))
conn.commit()
非常感谢。你知道吗
您需要使用
x
变量来构造value
。替换:使用:
作为旁注,使用
eval()
-it is dangerous通常不是一个好主意,请参见:相关问题 更多 >
编程相关推荐