0

I have 3 classes in my project. One is a DB class where I have the DB connection for my project, which looks like this.

class DB:
    def __init__(self):
        self.createConnection()

    def createConnection(self):
        db = DataBase(
            [config.endpoint],
            http_auth=(config.username, config.password),
            scheme="https"
        )
        self.__db = db

Now in other classes I want to access and use self.__db How can I use this? My 2nd class is a helper class:

import db

class Helper:
    def connection(self):
        db = db.createConnection()
        self.__db = db
        print(self.__db)
khelwood
  • 55,782
  • 14
  • 81
  • 108
Zain
  • 49
  • 6
  • 1
    Does this answer your question? [Creating a singleton in Python](https://stackoverflow.com/questions/6760685/creating-a-singleton-in-python) – luk2302 Sep 23 '22 at 11:17

0 Answers0