小编Ho *_*ong的帖子

使用 python 打开数据库文件 (.db)

我有一个 SQLite3 格式的数据库文件 .db,我试图打开它以查看其中的数据。下面是我使用 python 编码的尝试。

    import sqlite3

    # Create a SQL connection to our SQLite database
    con = sqlite3.connect(dbfile)

    cur = con.cursor()

    # The result of a "cursor.execute" can be iterated over by row
    for row in cur.execute("SELECT * FROM "):
    print(row)

    # Be sure to close the connection
    con.close()
Run Code Online (Sandbox Code Playgroud)

对于这一行("SELECT * FROM "),我知道您必须在“FROM”一词之后放入表格的标题,但是,由于我什至无法首先打开文件,因此我不知道该放置什么标题。因此,我该如何编码才能打开数据库文件以读取其内容?

python sqlite

5
推荐指数
2
解决办法
9124
查看次数

标签 统计

python ×1

sqlite ×1