Created
September 19, 2022 17:22
-
-
Save GGontijo/08e002dd0e5b5bd5daa462d8a490e6be to your computer and use it in GitHub Desktop.
Helper to import a configuration file written in .json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
class Config: | |
'''Singleton approach''' | |
_instance = None | |
def __init__(self) -> None: | |
CONFIG_FILE = 'conf.json' | |
with open(CONFIG_FILE, 'r') as config: | |
self.__config = json.load(config) | |
def get_config(self, var: str) -> str: | |
value = self.__config[var] | |
return value | |
def __new__(cls): | |
if cls._instance is None: | |
cls._instance = super().__new__(cls) | |
return cls._instance |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment