Skip to content

Instantly share code, notes, and snippets.

@GGontijo
Created September 19, 2022 17:22
Show Gist options
  • Save GGontijo/08e002dd0e5b5bd5daa462d8a490e6be to your computer and use it in GitHub Desktop.
Save GGontijo/08e002dd0e5b5bd5daa462d8a490e6be to your computer and use it in GitHub Desktop.
Helper to import a configuration file written in .json
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