使用Python列表MySQL更新Col值
我在下面给出的代码中阅读了一列的长度。然后,我有一个列表fakenames
其长度等于列的原始长度。
如何用我的列表fakenames
值替换原始列person_names
的值?更改应反映在数据库中。
import MySQLdb
# Connect
db = MySQLdb.connect(
host="abc.us-east-1.rds.amazonaws.com",
user="abc",
password="password",
)
cursor = db.cursor()
# Execute SQL select statement
cursor.execute("SELECT COUNT(person_names) FROM z3_table")
number_of_names = (cursor.fetchone()[0])
print(number_of_names)
fakeNames = []
# Commit your changes if writing
# In this case, we are only reading data
# db.commit()
# Close the connection
db.close()
这意味着从列表中的每个值fakenames
都应在其他行中。
I read a column's length in the code given below. Then, I have a list fakeNames
whose length is equal to the column's original length.
How can I replace the values of the original column person_names
with my list fakeNames
values? The changes should be reflected in the database.
import MySQLdb
# Connect
db = MySQLdb.connect(
host="abc.us-east-1.rds.amazonaws.com",
user="abc",
password="password",
)
cursor = db.cursor()
# Execute SQL select statement
cursor.execute("SELECT COUNT(person_names) FROM z3_table")
number_of_names = (cursor.fetchone()[0])
print(number_of_names)
fakeNames = []
# Commit your changes if writing
# In this case, we are only reading data
# db.commit()
# Close the connection
db.close()
This means that each value from the list fakeNames
should be in a different row.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论