Hello,
 I'd appreciate your suggestions for a better approach to the following task.

I have 2 files ( 2 classes). One (ClassA) has all logic related to the main 
workflow of the program. Another (DB), I like to offload all operations with a 
DB ( sql3 in this case).

I'm trying to pass the connection to the main class, but having problems. One 
of them, is i can't pass the conn as a parameter to the function in one 
(ClassA.abc()), because i inherit it ( function abc() ).
I created a self.DBConnection field, but i'm not sure if i'm on the right 
path...
Code is gutted to highlight the problem.

Thank you

--- code -----

one.py:
from .DB import *

class ClassA(OtherObject):

        def __init__(self):
                
                self.DBConnection = sql3.Connection

        
        def abc(self, reqId: int):
                DB.writeTicks(self,self.DBConnection,reqId))


DB.py:
import sqlite3 as sql3
import sys
from .tws import TWS
from utils import current_fn_name


class DB(object):
        db_location = ''
        # db_location = '../DB/pairs.db'

        def __init__(self, location='../DB/pairs.db'):
                db_location = location
                print(current_fn_name(),' self.db_location = 
{}'.format(db_location))

                try:
                        with open(db_location) as file:
                                pass
                except IOError as e:
                        print("Unable to locate the Db @ 
{}".format(db_location))

        def reqConnection(self):
                try:
                        con = sql3.connect(self.db_location)
                        con.text_factory = str

                except sql3.Error as e:
                        print("Error %s:".format( e.args[0]))
                        sys.exit(1)
                return con

        def write(self, con : sql3.Connection, tickId: int):
                        con.execute( blah) 

-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to