Apr-09-2020, 06:20 PM
I'm trying to create the Class object, but I'm unsure how to pass the arguments compared to my function based code?
import pyodbc import csv import logging import sys server = '' database = '' username = '' password = '' table = '' class SQLConnection(object): def __init__(self, driver, host, dbname, uname, pswd): connectstring = 'DRIVER=%s;SERVER=%S;PORT=1433;DATABASE=%s;UID=%s;PWD=%s;' % (driver, host, dbname, uname, pswd) self.connection = pyodbc.connect(connectstring) def getcursor(self): return self.connection.cursor() def select_from_database(self, tablename): cursor = self.getcursor() cursor.execute("SELECT * FROM %s " % tablename) row = cursor.fetchone() while row: print("%s %s" % (row[0], row[1])) row = cursor.fetchone() return row