Python 使用新值更新sql中的行
我正在研究python。我想用新值更新sql的每一行。 我的代码是:Python 使用新值更新sql中的行,python,mysql,Python,Mysql,我正在研究python。我想用新值更新sql的每一行。 我的代码是: val = cursor.execute("select id from tweeter1") words= processedRow.split() fdist2=len(words) for id1 in val: cursor.execute("""UPDATE TWEETER1 SET t1=%s where id = %s""",(fdist2,id1)) db
val = cursor.execute("select id from tweeter1")
words= processedRow.split()
fdist2=len(words)
for id1 in val:
cursor.execute("""UPDATE TWEETER1 SET t1=%s where id = %s""",(fdist2,id1))
db.commit()
当我执行这段代码时,我得到一个错误,说:
对于val中的id1:
TypeError:“long”对象不可编辑
我们将非常感谢您的帮助。谢谢您必须迭代光标对象:
cursor.execute("select id from tweeter1")
words = processedRow.split()
fdist2 = len(words)
for id1 in cursor.fetchall():
cursor.execute("""UPDATE TWEETER1 SET t1=%s where id = %s""",(fdist2,id1))
db.commit()
但只要将所有行更改为相同的值,就只需更新一次,而不需要任何where子句:
words = processedRow.split()
fdist2 = len(words)
cursor.execute("""UPDATE TWEETER1 SET t1=%s""",(fdist2,))
db.commit()
必须在光标对象上迭代:
cursor.execute("select id from tweeter1")
words = processedRow.split()
fdist2 = len(words)
for id1 in cursor.fetchall():
cursor.execute("""UPDATE TWEETER1 SET t1=%s where id = %s""",(fdist2,id1))
db.commit()
但只要将所有行更改为相同的值,就只需更新一次,而不需要任何where子句:
words = processedRow.split()
fdist2 = len(words)
cursor.execute("""UPDATE TWEETER1 SET t1=%s""",(fdist2,))
db.commit()
”
?这是干什么用的?@juergend…这就是Python如何定义允许单引号和双引号的字符串。”
?那是干什么的?@juergend。这就是Python分隔允许单引号和双引号的字符串的方式。对于游标中的id1,fetchall()无法在中复制多列中的不同值。我不想复制游标中id1的所有列中的相同值。fetchall()无法在中复制多列中的不同值。我不想在所有列中复制相同的值