【发布时间】:2017-01-19 19:14:56
【问题描述】:
我的代码如下:
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!')
当代码到达 db.cursor() as c: 的行时,程序给出以下错误
with db.cursor() as c: AttributeError: __exit__
我做错了什么?
【问题讨论】:
-
游标不支持上下文管理器。你不能和它一起使用
with。