0

我想将 MySQL 查询的结果存储在一个变量中(Python)

sql = "SELECT * FROM movies"
result = cursor.fetchall()
for row in result:
    movies = row[1]

print(movies)

(只打印最后一行)

4

1 回答 1

0

movies = row[1]movies是一个变量,将只有 for 循环中的最后一个元素。

你需要创建一个列表movies

movies = []

for row in result:
    movies.append(row[1])

print(movies)
于 2013-02-14T10:15:05.723 回答