python AttributeError: ‘MysqlDb‘ object has no attribute ‘cur‘

created at 06-19-2022 views: 29


The code has been reporting errors and has been unable to execute. I have read the code for a long time, and I have read it for a long time according to the information reported, but I have not seen any problems.

Traceback (most recent call last):
  File "C:\Users\Administrator\PycharmProjects\pythonProject\util\", line 16, in <module>
    r = mydb.query("select * from `case`")
  File "C:\Users\Administrator\PycharmProjects\pythonProject\util\", line 10, in query
AttributeError: 'MysqlDb' object has no attribute 'cur'
import pymysql

class MysqlDb:

    def __int__(self):
        self.conn = pymysql.connect(host="", user="root", password="123456", database="testcase")
        self.cur = self.conn.cursor(cursor=pymysql.cursors.DictCursor)

    def query(self,sql):
        data = self.cur.fetchall()
        return data

if __name__ == '__main__':
    mydb = MysqlDb()
    r = mydb.query("select * from `case`")
    #r = mydb.execute("insert into `case` (`app`) values('xd')")


Through code comparison, it is found that when __init__ is called, __int__ is brought out inexplicably. What a shame, I am really speechless. The key is that the error message is wrong!


Auto-completion is still to be seen clearly, the information given by the python error report may not be accurate.

created at:06-19-2022
edited at: 06-19-2022: