gpt4 book ai didi

Python 序列 id 到 mysql 与文本

转载 作者:行者123 更新时间:2023-11-29 21:37:10 24 4
gpt4 key购买 nike

我正在尝试使用常量字符串创建 ID 号。但是当我执行该程序时,它会插入输入数字乘以我的输入值。我只想添加如下内容:

dgNotListesi_txtGelisimDrumu_0dgNotListesi_txtGelisimDurumu_1dgNotListesi_txtGelisimDurumu_2dgNotListesi_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 = "dgNotListesi_txtGelisimDurumu_%s" %y

与:

value = "dgNotListesi_txtGelisimDurumu_%s" % x
<小时/>

顺便说一句,使用 eval() 通常不是一个好主意 - it is dangerous ,参见:

关于Python 序列 id 到 mysql 与文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34839933/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com