我正在尝试使用 python 测试以下内容,但出现无效的语法错误:
db = None
try:
db = mdb.connect("localhost","user","pass","dbName")
with db:
cur = db.cursor()
cur.execute("SELECT * from product")
rows = cur.fetchall()
for row in rows:
print row
except mdb.Error, e:
print "Error %d: %s" % (e.args[0],e.args[1])
sys.exit(1)
错误如下:
File "script.py", line 11
with db:
^
SyntaxError: invalid syntax
我该如何解决?