I have simple class to fetch query from database .
# myClass.py
class DB:
def __init__ (self, host, user, password):
self.conn = MySQLdb.connect("localhost","****","****","***")
self.conn.set_character_set('utf8mb4')
cursor = self.conn.cursor()
cursor.execute('SET NAMES utf8mb4;')
cursor.execute('SET CHARACTER SET utf8mb4;')
cursor.execute('SET character_set_connection=utf8mb4;')
def query(self, q):
cursor = self.conn.cursor()
cursor.execute(q)
return cursor
If I use the below query with it works ok,
from myClass import DB
q = DB("..", "..", "..", "..")
_fetch = q.query("... ")
However if I would like to get rid of the second line since I am declaring user, pass, host .. in myClass.py
So, when I try
from myClass import DB
_fetch = DB.query("... ")
it won't allow me to connect, even if I remove the self,
keyword for query