【原创】 MySQLdb.cursors&nb…

来源:互联网 发布:hl线切割编程加工视频 编辑:程序博客网 时间:2024/05/01 12:20
原来ubuntu 12.04 python-mysqldb只需要importMySQLdb就可以使用MySQLdb.cursors.DictCursor(字典游标)

不过最近不知道python的原因还是mysqldb的原因,应该是python-mysqldb版本问题吧,
Traceback (most recent calllast):
  File "", line 22,in
AttributeError: 'module' object has noattribute 'cursors'
MySQLdb.cursors 分离出去了,需要单独import。

针对旧代码解决方案,
一、 行首 import MySQLdb.cursors.DictCursor
二、
1.  zhipeng@ubuntu:~$ python -c "importMySQLdb as mysqldb; print mysqldb.__file__"
/usr/lib/python2.7/dist-packages/MySQLdb/__init__.py
2. sudo su
3. echo "import cursors" >>/usr/lib/python2.7/dist-packages/MySQLdb/__init__.py
4. zhipeng@ubuntu:~$ python -c "import MySQLdbas mysqldb;print mysqldb.cursors"
0 0