Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想将 MySQL 查询的结果存储在一个变量中(Python)
sql = "SELECT * FROM movies" result = cursor.fetchall() for row in result: movies = row[1] print(movies)
(只打印最后一行)
movies = row[1]这movies是一个变量,将只有 for 循环中的最后一个元素。
movies = row[1]
movies
你需要创建一个列表movies
movies = []
做
for row in result: movies.append(row[1]) print(movies)