使用Python列表MySQL更新Col值

发布于 2025-02-08 09:48:28 字数 682 浏览 2 评论 0原文

我在下面给出的代码中阅读了一列的长度。然后,我有一个列表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_nameswith my list fakeNamesvalues? 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 fakeNamesshould be in a different row.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文