小编Mic*_*ael的帖子

Python数据库sqlite3

我有一个小程序,代码如下:

def get_code(hex_pattern, database='./AndroidLockScreenRainbow.sqlite'):
    try:
        if os.path.exists(database):
            with lite.connect(database) as db:
                with db.cursor() as c:
                    c.execute("SELECT * FROM RainbowTable")
                    rows = c.fetchall()
                    for row in rows:
                        if row[0] == hex_pattern:
                            return row[1]
        else:
            raise lite.OperationalError("Database file not exists")
    except lite.OperationalError:
        print('Given SQL table not found!')
Run Code Online (Sandbox Code Playgroud)

当代码到达 db.cursor() as c: 的行时,程序给出以下错误

with db.cursor() as c:
AttributeError: __exit__
Run Code Online (Sandbox Code Playgroud)

我有什么错吗?

python sqlite

3
推荐指数
1
解决办法
2136
查看次数

标签 统计

python ×1

sqlite ×1