python getting syntax error in except
Question: I am new to python and just been playing with the database API. I am getting
an invalid syntax error in the exception except block comma. I can't figure
out any syntax mistakes. Below is the code I am using

    
    
    import time
    import MySQLdb
    import sys
    import urllib2
    
    #f = open("../", 'r')
    
    try: 
        db = MySQLdb.connect(host="localhost", user="test", passwd="test",db="test")
        cur = db.cursor()
    
    except MySQLdb.Error, e:
        print "Error %d: %s" % (e.args[0], e.args[1])
        sys.exit (1)
    
    finally:
        cur.close()
        db.close()
    #f.write('amal')
    #f.close()
    


Answer: Your syntax is correct _for Python 2_ , which would be the correct version
given the fact that you tried to import `urllib2` here.

For recent Python versions the `except` syntax was updated, and the old syntax
no longer works in Python 3. The correct syntax would be:

    
    
    except MySQLdb.Error as e:
    

but you'll need to fix what Python version you are running this with _or_ use
the correct libraries for Python 3. That means using `urllib.request` and
installing `MySQLdb` for your Python 3 installation first.

