Doing the tutorial. How to understand why a mistake?

There is a class:

class UseDatabase:
def __init__(self, config: dict) -> None:
self.configuration=config

def __enter__(self) -> 'cursor':
self.conn=mysql.connector.connect(**self.configuration)
self.cursor=self.conn.cursor()
return self.cursor

def __exit__(self, exc_type, exc_value, exc_trace) -> None:
self.conn.commit()
self.cursor.close()
self.conn.close()

Then, in the edit window:

>>> from DBcm import UseDatabase
>>> dbconfig={'host':'127.0.0.1', 'user':'vsearch', 'password':'pass', 'database
':'vsearchlogDB'}
>>> with UseDatabase (dbconfig) as cursor:
... _SQL="""show database"""
... cursor.execute(_SQL)
... data=cursore.fetchall()
...
Traceback (most recent call last):
File "", line 1, in
File "C:\Users\администратор\.PyCharm2019.2\config\scratches\DBcm.py", line 8,
in __enter__
self.conn=mysql.connector.connect(**self.configuration)
AttributeError: 'UseDatabase' object has no attribute 'mysql'
>>>

I can not understand why an error in the tutorial all the way and recorded
April 3rd 20 at 17:19
1 answer
April 3rd 20 at 17:21

Find more questions by tags Python