I am trying to test the following with python but I get the invalid syntax error:
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)
The error is the following:
File "script.py", line 11
with db:
^
SyntaxError: invalid syntax
How do I fix this?
SyntaxErrorand format the first couple of lines of your code exactly as you have them in your script?withstatement is available from python 2.5+. That's pretty much why it will never work. python.org/dev/peps/pep-0343