MySQL: AttributeError: cursor

Albert W. Hopkins marduk at letterboxes.org
Sat Feb 11 19:07:25 CET 2012


On Sat, 2012-02-11 at 09:40 -0800, Kevin Murphy wrote:
> Hi All,
> I'm using Python 2.7 and having a problem creating the cursor below.
> Any suggestions would be appreciated!
> 
> import sys
> import _mysql
> 
> print "cursor test"
> 
> db =
> _mysql.connect(host="localhost",user="root",passwd="mypw",db="python-
> test")
> 
> cursor = db.cursor()
> 
> >>>
> cursor test
> 
> Traceback (most recent call last):
> File "C:\Python27\dbconnect.py", line 8, in <module>
> cursor = db.cursor()
> AttributeError: cursor

You are using the low-level C API wrapper (not sure why).  Most people,
I believe, would use the pythonic API:

>>> import MySQLdb
>>> db = MySQLdb.connect(host='localhost', user='root', passwd='mypw',
db='python-test')
>>> cursor = db.cursor()

The low-level API is... well.. for when you want to do low-level stuff.
You probably want the pythonic API.

-a





More information about the Python-list mailing list