我是Python的新手。我从连续体安装了anaconda,从Pypi安装了MySQLdb。我正在努力在spyder中运行这段代码。
import MySQLdb
class db_class:
def __init__(self,db):
self.Mdb = MySQLdb.connect(host='localhost',
user='root',
passwd='',
db=db)
self.Mcursor = self.Mdb.cursor()
def __del__self(self):
self.Mcursor.close()
self.Mdb.close()
def execute(self,Aquery):
return self.Mcursor.execute(Aquery)
def fetchall(self):
return self.Mcursor.fetchall()
def fetchone(self):
return self.Mcursor.fetchone()
def description(self):
return self.Mcursor.description
if __name__=="__main__":
db=db_class('XXX')
我在ipython控制台中得到这个:
File "C:/Users/...", line 12, in __init__
self.Mdb = MySQLdb.connect(host='localhost',
AttributeError: 'module' object has no attribute 'connect'.
MySQL已安装在以下路径中
C:\Users\Anaconda2\Lib\site-packages\
。谢谢你的帮助。