spyder MySqldb模块没有“connection”属性

2024-10-01 02:27:41 发布

您现在位置:Python中文网/ 问答频道 /正文

我对Python很陌生。我从continuum安装了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控制台上看到了这个:

^{pr2}$

MySQL已安装在以下路径中 C:\Users\Anaconda2\Lib\site-packages\。谢谢你的帮助。在


Tags: selfcloseexecutedbreturndefdescriptionclass