i'm trying to connect to a database building a class connection()saved in local folder in file utils.py .This is what i worked so far of it:
class connection:
def __init__(self):
self.conn = MySQLdb.connect(host = "localhost",user = "xxx",
passwd = "xxx", db = "xxx",
cursorclass=MySQLdb.cursors.DictCursor)
def TearDown(self):
self.conn.close()
def nume(self):
return self.conn
and this is where i use it in code:
from utils import execute_sql,connection
con = connection.nume()
cursor = con.cursor()
....
cursor.execute(sql)
...
connection.TearDown()
i tryed several more but this way was the simplest, still getting some errors that i struggle with;