Created
May 30, 2017 15:08
-
-
Save arthuralvim/48db37817da64e63bd520bca1e82aa97 to your computer and use it in GitHub Desktop.
Config Loader
This file contains hidden or 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
# AWS Lambda Coding & Config (part 4) | |
# Ben Emson | |
# https://www.youtube.com/watch?v=o-8U_3s_zWI | |
import os | |
import json | |
class ConfigLoader(object): | |
CONFIG_FILE = 'config.json' | |
def config(self): | |
""" Parse configuration. """ | |
config_file = os.path.join( | |
os.path.dirname(os.path.realpath(__file__)), | |
self.CONFIG_FILE) | |
if not hasattr(self, '_parsed_config'): | |
self._parsed_config = self.load(config_file) | |
return self._parsed_config | |
def load(self, config_file): | |
""" Read JSON file and assign it to an instance variable. """ | |
with open(config_file) as data_file: | |
self._parsed_config = json.load(data_file) | |
return self._parsed_config |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment