从sqlite3获取数据并保存在列表中

2024-05-29 10:55:40 发布

您现在位置:Python中文网/ 问答频道 /正文

我想从sqlite3数据库中获取数据并将它们保存在列表中

conn=sqlite3.connect("words.db")
cur=conn.cursor()
cur.execute("SELECT word FROM words WHERE state='positive'")
rows=cur.fetchall()
conn.commit()
conn.close()
print(rows)

行的输出如下所示:

[('abound',), ('abounds',), ('abundance',)]

我希望:

['abound', 'abounds', 'abundance']

我用以下内容创建了数据库:

cur.execute("CREATE TABLE IF NOT EXISTS words (id INTEGER PRIMARY KEY, word TEXT, meta TEXT)")

Tags: text数据库列表executedbconnectconnsqlite3

热门问题