Feb 11, 2012 5:40 pm
Kevin MurphyHi 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()
>>>
Traceback (most recent call last):
File "C:\Python27\dbconnect.py", line 8, in <module>
cursor = db.cursor()
AttributeError: cursor
Feb 11, 2012 6:07 pm
Albert W. HopkinsOn 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
> 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()
>
> >>>
>
> 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 = MySQLdb.connect(host='localhost', user='root', passwd='mypw',
>>> 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
Previous Thread: ANN: Sarge, a library wrapping the subprocess module,has been released.
Next Thread: Stopping a looping computation in IDLE 3.2.x
Related Forum Topics
- Py 3.2: sqlite can't operate on a closed cursor
- Is there a way to creat a func that returns a cursor that can be used?
- AttributeError in "with" statement (3.2.2)
- Context Manager getting str instead of AttributeError instance
- AttributeError: 'module' object has no attribute 'logger'
- Query from sqlalchemy returns AttributeError: 'NoneType' object
- Debugging difficulty in python with __getattr__, decorated propertiesand AttributeError.
- Will MySQL ever be supported for Python 3.x?
- SQLAlchemy: How to do Table Reflection and MySQL?
- Why Doesn't This MySQL Statement Execute?